Why does the US government not invest in the stock market?
The US government could do that but policies prohibit this, since buying a specific company's stock benefits the shareholders of that company.
This would be a huge conflict of interest.

Another answer by Paul Mulwitz,  an online commentator, says “If the government bought ownership in private companies they would no longer be private companies.  “

A good example would be if the US government invested in Apple computers.  Would it act against the company in case of a violation?
There would be a conflict of interest.

Side note, What does the government invest in?

According to the CBO (https://www.cbo.gov/publication/55375) in 2018, the federal government spent $492 billion on investment—for physical capital, education and training, and research and development—which represented 12 percent of federal spending and 2 percent of GDP.