Basic science is often cheap, I don't know where you're getting it's generally expensive. I've yet to meet someone whose equipment costs as much as any of the stuff my friends design for defense contractors. Even the head of the lab I'm in is making less than my friends are making as engineers and the lab equipment is pretty cheap compared to the stuff my friends are designing (we have a radar that cost maybe a couple hundred thousand but that's the majority of the equipment cost for the past decade).
Idk what your idea of budgets are for these sorts of labs but I think most engineers would be shocked at the shoestring budgets they run on (at least the ones I know are a fraction of the cost of a single engineering team).
The “whole thing” is never cheap. Running something like a university — providing the environment, infrastructure, administration, facilities, compliance systems, equipment, libraries, grants offices, laboratories, and institutional platform that allow professors and graduate students to do research — is itself extremely expensive.
After all, if you look at the fiscal budgets of major economies, public spending on education and research is often much larger than military spending.
Then again, military weapons are indeed insanely expensive.