It's perfectly legal/ethical, but it would not be open source at that point. Same as licenses that prevent companies from running the licensed product as a cloud service, even if the source is freely available to view or use in a private capacity.
You can of course create such a license, but it would not be an open source license, more like a shared source license or ethical license or something else.