- There are big problems we want solved that have no associated revenue. For example consider the problem of taking care of the million or so untreatable schizophrenics in the USA. (I estimated that number by knowing that the USA has 300 million people, about 1% of people have schizophrenia at some point in their life, and of those about 1/3 spontaneously recover, 1/3 respond to treatment, and 1/3 are not treatable.) Left to their own devices these people are unable to function. No matter how loving their families, family resources get severely strained supporting them. And there is no realistic hope of integrating them into society. As a society we do not wish to kill them and do not want them starving to death, so we need to take care of them. The magnitude of the problem is more than charity can support, so this is a valid role for the government. (Total charitable giving in the USA is about $300 billion/year. If we assume that institutionalizing a person in a place with medical care costs $30,000/year, then that would suck up 10% of all charitable giving. On just one cause.)
- Capitalism ignores external costs. A rational profit seeking individual who can acquire revenue and leave costs for others, will. A classic example is pollution. Pollution is a diffuse cost that is shared by an entire community and is mostly not experienced by the polluter. Therefore polluters have little incentive to reduce pollution. Government regulation can solve the problem by artificially providing the incentive.
- Capitalism ignores external benefits. What do universal education, basic research, and sound policing have in common? The providers of the benefit cannot readily recoup the benefit they provide. Poor kids who will do better with an education are poor right now, their parents can afford that education. It is the nature of research that it proceeds best by sharing ideas, but when ideas are shared then there is generally little or no connection between the people who did the basic research and the people who commercialize it. Law and order is great, but the people who enforce the law aren't generally the people who build businesses that can prosper because they exist within a well-regulated society. Private markets therefore are poor at allocating any of these things.
- Capitalism has perverse incentives with asymmetric information. As an individual you are in an extremely poor position to judge whether cooks at a local restaurant wash their hands, the security of a safe, or how effective a medical treatment is. So people judge on the basis of things they can see that they hope are a good proxy for what they want to know. Such as the quality of the decor, how sturdy the safe looks, and the presentation of the person selling you the treatment. But you can fake those without providing the attribute people really want. As a result private markets left to their own devices will provide unhealthy restaurants, insecure products, and unreliable treatments. (Government is good about public health, only rarely intervenes in security, and frequently doesn't pay attention to effectiveness of treatments. If you know where to look, this shows.)
None of this is to say that we want or need government intervention in everything. As I said, capitalism is incredibly effective at generating economic activity, much of which benefits us all. Besides, government has its own characteristic failure modes, which are at least as bad, if not worse, than the ways that capitalism fails.
However when there is a solid justification for government intervention, usually one of these failure modes in free markets is behind it. And if you can identify no specific reason why free markets should do a bad job in that area, then odds are good that the effects of the government intervention is somewhere between ineffective and bad.