It wouldn't be cost-effective in China either were it not for state support.
There is no doubt that global free trade in commodities, in the absence of any government support, would be the most economically efficient thing to have. But China -- probably correctly -- identifies dependency on foreign supply chains for critical materials as a *security* issue. So they have indirect and direct subsidies, as well as state owned enterprises that operate on thin or even negative profit margins.
Since China does this kind of support on a scale nobody else does, China produces more rare earths than any other country, even though it is not particularly well endowed with deposits. This solves China's security problem with the reliability of the supply, but creates a security problem for other countries.
China thinks like Japan did before WW2, like empire building European countries did in the 1800s. Control over resources is a national security weapon, both for defense and offense.