Well that’s an incorrect sweeping statement. Depends what is in your contract.
My contract says I have to have approval from my employer to moonlight for anyone else.
If they found out I was moonlighting without prior agreement I would be in breach of contract, and hence they could terminate my contract and I would have no legal recourse.