The US Navy, like all parts of the DOD, knows that the best way to build support for any weapons system is to have part of it manufactured in a Congressman's district. The most unsinkable projects are built, little by little, in 435 districts.
So, yes, the shipyards need to be on the coast. But much of the material on the inside of the ship may be built elsewhere.
People are allowed to move for work. I have. Shipyards are expanding in the Great Lakes region.
https://maritime-executive.com/article/navy-expands-shipbuil...
The shale gas revolution has created a lot of blue collar jobs. The chemicals industry is booming in Ohio.
https://www.jobsohio.com/news-events/news-press/energy-chemi...