BEIJING—Chinese companies are turning to an unlikely source for profits in the soft economy: the country’s red-hot stock markets.

Take Dong Jun, who earlier this year shut down his factory making lighting equipment and electrical wiring and let go some 100 workers. The 50-year-old comes to the plant in the eastern city of Yancheng almost daily, but spends his time trading stocks on behalf of his company, Yanwu Keda Electric Co.

“Manufacturing is a very hard business these days,” said Mr. Dong, chairman of the company. “I want to make some money from the stock market and use the profits to restart my manufacturing business later, when the economy turns for the better.”

Chinese companies are finding stock investing an attractive option as the wider economy struggles with tepid demand, excess industrial capacity, persistently high borrowing costs and other troubles. Their interest poses a challenge for policy makers, who want to nurture markets companies can tap for investment capital, rather than creating a venue for speculation.