The public has had substantial loss of faith in its institutions in the past couple of decades, and the military is not exempt from it. America's foreign policy has come a long way since WWII.
Politics aside, I've also seen cynicism towards Silicon Valley tech from the defense world- USAF vet and commentator Mike Black's vitriolic criticism of Anduril and other defense startups, for instance (e.g. https://threadreaderapp.com/thread/1575677683211505665.html https://twitter.com/mikeblack114/status/1730453326817276026 https://twitter.com/MikeBlack114/status/1736481633358770353 https://twitter.com/MikeBlack114/status/1741366626006560864). Though that is tangential to your point.
But I don't think all is lost. I'm pretty sure solidly civilian organizations like United States Digital Service and 18F have good reputations, much like the Postal Service does. But all of them receive a pittance of investment compared to defense spending.
At the cultural level, though, during periods like the space race and cold war, there seemed to be a national zeitgeist such that companies, their owners, their directors, were all willing to sacrifice some profit to serve a common national mission. Maybe it was just the fact that the CEOs had grown up in a time when food was rationed and factories were ordered by federal fiat to produce war materiel.
I don't actually think this type of culture is completely dead, for what it's worth. But it's not exactly in vogue. I personally work in defense, I served in the Army, and I make more than enough money but quite a bit less than Netflix likely would have paid me, but I work on products that serve US strategic interests. Entire companies exist explicitly for this purpose, but they're not Google scale and never will be. I don't think very many people on Hacker News would even consider this good, though. Witness the backlash to OpenAI even being willing to work on military applications at all. The readership is so cynical that they can't imagine a military serving any purpose aside from valueless destruction. In the 20th century when militaries saved the world from German and Japanese conquest and mass genocide, that kind of thinking was a lot less prevalent.
I also don't think these are the only two options, either. People can also be motivated purely by the science itself or by the global wellbeing of all mankind. I just don't know that, historically speaking, those bring large-scale resource mobilization to bear quite as well as getting rich and ensuring the continued strategic dominance of a way of life represented by a country of birth you deeply believe in. As people come to believe less and less in their own countries, we seem to be left mostly with getting rich as the only viable option.