Yes, you can run Xcode in a VM or emulator running macOS.
The reason you can't run Xcode on Linux directly (i.e. not in an emulator or VM) is that nobody has done the work. The people with the expertise to do it are Apple, and they haven't done so and are unlikely to do so.
Some reasons Apple doesn't provide Xcode for Linux (a la Visual Studio) are that 1) Apple is in the business of selling computers, so they benefit directly from requiring iOS and macOS developers to buy Macs, and 2) Xcode is written for macOS, so it requires a large portion of the macOS ABI and runtime in order to run. Also 3) Apple is in the process of switching from x86 to Apple Silicon. Although there are ARM-based Linux systems, they may not be 100% compatible with Apple's M1 and other chips.
There is little to no business or technical incentive for Apple to do the large amount of work required to either port Xcode to Linux (especially x86 Linux) or to create a virtual macOS environment (analogous to WINE) for running macOS software on Linux. The GNUStep project created a fair amount of the Objective-C/NeXTSTEP environment and enabled some macOS apps to be cross-compiled for Linux, but a great deal of work would be required to create a complete environment capable of either cross-compiling or running Xcode (or other large macOS apps) on Linux.
> MacOS could be running headless inside a docker container,
Linux containers are for native Linux executables, not foreign OS kernels. To run an OS kernel, you need a virtual machine monitor like kvm or virtualbox.
TL;DR: Use virtualization.