For the organizations and countries involved, this helps provide for an advanced industrial base that continues to build and drive an ecosystem that supports powerful economic engines.
Another major reason governments fund research is to produce people with PhDs. This is why the apprenticeship structure of academia is so sticky, and why in order to get tenure professors have to graduate students.
Unless they don't mind working for peanuts, in which case there's no problem.
1. Society uses price signals to drive activity to areas "we" want to develop
2. In research, the tournament model prevails so a few winners get most of the gains
However, the question arises:
The tournament model prevails in many other domains including startups, the movie industry and so forth. However, in those areas most people don't feel that the enterprise is severely underfunded. (I am assuming this so if people have contrary data, I will re-assess).
The question stands: in spite of the tournament model, why does society fail to deliver enough reward for basic research when we as a society believe that there should be more of it.
(We could ask the same of teachers, and so on.)
It could also be the case that "society", whatever that is, doesn't really feel that science is underfunded.
Repeat for grad school->postdoc, postdoc->tenure track, and so on.