I think government has two legitimate purposes.
1) Force people to fulfill their moral obligations when they might not do so under the honor system. People have moral obligations, whether these are negative obligations like not committing crimes or positive obligations like doing what you agreed to in a contract. Society should make sure these obligations are fulfilled. If we can do so without government that’s great, but if not it is legitamate to use coercive, statist government to make sure these things get done.
One refrain I have heard from libertarians is, “Government cannot give anything to anybody that it doesn’t first take from somebody else.” The idea being that government is nothing more than a common theif. I have a more expansive idea than libertarians of what positive moral obligations people have. When people work just as hard and take the same risks but get different results due to forces outside their control they have a duty to even out those effects of undeserved luck. Government taking money from someone to give it to someone else can be a legitimate act of forcing someone to fulfil their obligations. Libertarians complain that this doesn’t create wealth, but creating wealth isn’t the purpose of it. The purpose is ensuring fairness by making people live up to their obligations.
Not every case of government transferring money from one person to another falls under this legitamate purpose. There are a lot of instances where government programs are just unfair boondoggles for some special interest.
2) The second purpose of government is to create value in a small number of cases where the private sector has trouble. For this I’m thinking of things like the interstate highway system, a local water utility, or fundamental science research. There are goods where fundamental features of the good make it hard for the market to supply it efficiently. These cases are rare, but they exist. Libertarians are right that society could get along without the government doing this, but less value would be created. We need to carefully consider cases when the inefficiency of government is better than the inefficiency of a non-governmental solution or not having the good at all.