It is to investigate new technologies (i.e. how do we control a thousand drones) and preserve domain knowledge in a large number of engineers spanning multiple generations. If all these engineers go work at $BIG_TECH optimizing ad revenue for watching short videos, we'll have to rediscover basics the next time.
When we have to fight the next serious war, we are not going to primarily use F-35 jets built twenty years ago, it's going to be something built on a similar platform in larger numbers to specifically address challenges of that era. If it can not be made cheap enough, whatever contractors involved are going to be nationalized. All major wars between comparable powers were fought with technology hot off the assembly lines, not billion dollar prototype models developed twenty years ago to bomb caves in deserts.
If you look at it from this angle, all the idiosyncrasies make sense. There's of course the inefficiency of defense contractors skimming off profits at multiple layers, but if you find a solution to that while preserving productivity, you'd win the economics nobel tomorrow.