Scientific research can be divided into two types: basic and applied. The purpose of basic research is to yield knowledge, while the purpose of applied research is to yield something with practical value. It may be tempting to argue that governments should only fund applied research—it is the intuitively "practical" choice—but this would be a bad idea.
First, applied research rests upon the foundation erected by basic research. All of the knowledge and techniques used in applied research have their origins in basic research. All of the work going into understanding the larger universe, for example, currently has very little practical application—why do we need to know about celestial bodies and the like when it might be centuries before we ever travel to them? But when humankind finally devises the means to send those first interstellar explorers off into the stars, it'll be thanks to the centuries of basic research that came before. The needs of the future are difficult to forecast. Therefore we cannot rule out scientific undertakings which have no immediate practical value.
Second, even if the results of basic research are not immediately applicable, we can at least examine how the research is conducted to hone our methodologies. That way, when scientists are conducting applied research that utilizes related concepts or methods, there will be some previous record or procedure to refer to. At the very least, the techniques pioneered in basic research should be transferrable to applied research. For example, say in the course of basic research on a certain chemical compound it is shown that they can be synthesized more efficiently using X method. The compound itself may be relatively valueless, but scientists doing applied research may look at how this more efficient process was arrived at and formalize a way to find cheaper solutions to synthesizing commercial chemicals.
It is true that the government could be spending their money on research with more immediate practical benefits—its duty is, after all, ultimately to foster the wellbeing of its citizens, and practical research can aid in that endeavor in more concrete ways. But if the government foregoes supporting knowledge for the sake of knowledge, then who will pick up the slack? Applied research can lean on private funding, because it is by its very nature a commercial undertaking. But basic research? Aside from foundations and wealthy philanthropists with a predilection for science, there would be nobody to support the march of scientific progress. As human beings we are more than just creatures of comfort—we are also knowers, and so furthering our understanding of the world should also fall under the rubric of government responsibility.
We cannot know where a particular line of inquiry will take us before we have arrived—otherwise, the act of inquiring would be pointless. Thus governments should at least fund basic research "just in case" a useful discovery is made. We also do not have to arrive at a useful destination to benefit from the inquisitive journey—the actual process of investigating might teach us as much as the answer we finally stumble upon. This is another reason funding for basic research should be dismissed out of hand. And last but not least, the pursuit of knowledge is a fundamentally human endeavor. The government should support if it seeks to aid in the flourishing of its citizens, because few others will step up to fill that role.