I think that the illegal (ish) part comes from Apple making macOS free if you're installing it on Apple hardware. They don't publicly license it for use on non-Apple hardware, although, I would guess that VMWare if not others has a license to run it on random x64 servers to test ESXi with because setting up a different testing environment of Mac Minis to test every change to their hypervisor on instead of using their normal testing infrastructure would be dumb.
(or they just do it anyway and don't tell Tim.)