They could operate there if they submitted themselves to Chinese government censorship (aka "local laws"). Google pulled out because it refused to. Facebook really wanted to (Zuck even made a trip there to talk to Chinese officials) but ultimately decided (correctly) that doing so would greatly hurt it in the US/Europe. Same for Twitter (pre-Elon).