First, a clarification, though it has become common to refer to "the government" as if it were some remote entity with its own thinking, it is simply a reflection of the society as a whole. Traditionally, republics are relatively slow to move in response to people's needs and desires, but overall are moved to meet people's needs as politicians respond to people's demands and votes. Today, that has been skewed because so much money and power is flowing from the top, there is less and less place for the individual.
Government needs to protect people in ways they are not able to individually protect themselves. That includes providing a base standard of living, because there is no such thing as a bottom for humanity in a free market, but humans (unlike products) do have a fundamental value. Or, to put it another way, its bad for business to have a bunch of starving folks all over the street... besides, if they can buy food, then a few grocers get to make money. (note.. that last is a real key, too often welfare and such are seen a simple donations that do no good else, but they actually do a lot to move our economy forward from the base up. Money given at the top, to contrast more often goes into a dark hole of failed ideas).
Similarly, the government must set safety standards for various businesses, because employers don't tend to listen to employees on that and even insurance companies can be too slow. (this does NOT mean I think our current system is perfect ... we do need more inbuilt controls so ensure that safety and not bureacracy or self-protection of specific business desires are shaping the rules)
A big role is to control damage to the environment, because by the time damage is severe enough to impact the economic stream, the damage is either very, very, very expensive to correct or not correctable at all.
Government has to provide necessary services, such as transportation, because if individuals or corporations are in charge, then those folks will quickly control the economy of the area.
Similarly, education must be universal and set by the government. As much as a society, free markets and enterprise depend on physical access, access to information is even more critical. Without education, there is no freedom.
Government sometimes must step in to control access to resources that are severely limited, so that a few don't dominate and take the resources and then charge too much. This might mean food and gas rationing in times of war or natural disaster.
It seems that healthcare is quickly emerging as another area where limits are needed, though in the case of health care a strict food and gas style rationing system won't work because healthcare is so much more complicated. (it needs to be a mixture of some market forces and some top down control, with in-built measures to ensure that science/medical evidence move the system, that it does not get stymied in bureacracy. We have a few models out there, but discussion of that belongs in other threads).