They are run by contractors because the US government does not have riveting or hull welding in its core competencies.
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.