It's fine for professional things, too. Just follow the 11th commandment and you'll be fine.
11th commandment? "Everything's ok as long as you don't get caught"?
There's no difference in the binaries built by Xcode running directly on Apple-branded hardware and Xcode running in a macOS VM in a generic (or perhaps metal, if nested virtualization isn't available) ec2 instance.
its however not permissable, as you cannot buy apple software without agreeing to their licence, which disallows running it on anything but apple hardware.
for private fun projects: possible
for professional things: a very bad idea