Some commercial shipbuilders, notably NASSCO, do business with the US Navy for smaller classes of ship as well as auxiliary vessels, and potentially could take orders from foreign militaries.
But yes, there is a massive domestic shipyard and shipbuilding industry in the US that is military-only. There are almost 300 active ships and another 170 in the reserve fleet, almost all with far more complex maintenance requirements than the typical civilian vessel.
Like many government operations, the US government doesn't try to oversee day-to-day operations, and awards those by contract. Same with the operation of national labs, for example.
They are operated by those contractors for a profit, profiting from the US government. The US government does not choose to establish and/or invest in yards, and grant operating contracts to those contractors, for the purpose of making a profit.
The US government does so in order to have a reliable source of naval construction and repair services in case of a military conflict.