There are a myriad of reasons why a factory owner would choose to open a factory in China.
At its base, economics requires one to control costs while charging the highest price that the market will allow for a product.
And so, if 1. the costs of production are lower in China or 2. the consumer is in China, it can be advantageous to create a product in China to be sold in China or elsewhere.