(There is something of a theory to that former bit - since the military may be your only customer, even if the govt isn't actively buying e.g. a tank they have to finance the continued existence of the industry. Y'know, the sort of thing that we should have been doing for COVID shutdown & other businesses, but I digress...)
This isn't a theory---the US military forbids a lot of things from being exported, and since civilians can't own things like modern MBTs, fighter jets, or plutonium pits for nuclear weapons, they have to make sure that the infrastructure stays put even when their demands (say, for new tanks) are minimal or even nonexistent, because it would be
slightly embarrassing if, say, we didn't maintain the industrial know-how as to what must be done to build tanks quickly and efficiently, and then ended up in a war where we needed more tanks.
And for what happens when you let a specialized industry like that dissolve for even as little as 15 years, well...look at the WWII German navy. Hideously inefficient ships (Bismarck, with protection, firepower, and speed inferior or merely equal to several 1920s designs yet a displacement very nearly fifty percent larger) with several nearly crippling design mistakes because the know-how for building warships properly had vanished due to the Treaty of Versailles.