It is not illegal for foreigners to own part of Chinese companies. It's generally illegal for a single foreign entity to own a controlling interest. Softbank and Yahoo invested into Alibaba relatively early on. It was incorporated in China. Their positions represented the majority of shares in the business, just not individually.