why do governments provide certain goods instead of leaving the provision of those goods to the free market?

Plenty of reasons.
1) the good could be a public good, like national defense. (look up the characteristics of a public good).
2) it could be a merit good, something that society, in general, believes everyone should have (food, housing or medical care).
3) it could be a good with strong positive externalities (e.g., basic education or public works of art),
4) it could be a good where it would be very difficult for a private firm to recover the good's development costs (e.g., basic medical research), or where the capital costs are too great for a private firm to handle (e.g., highways)
5) It could be a good we wouldnt want a private firm to exclusively provide (e.g., police protection or the criminal justice system).
6) the good could come primarily from a resource that we believe belongs to society in general (e.g., national parks
7) it could be something that governments have traditionally provided and we expect them to continue to provide (e.g., tours of the White House, or fireworks on 4th of july)

Governments provide certain goods instead of leaving the provision to the free market for a variety of reasons:

1) Public Goods: Some goods, such as national defense, have the characteristics of a public good. Public goods are non-excludable, meaning that it is difficult to exclude individuals from benefiting, and non-rivalrous, meaning that one person's consumption does not diminish another's. The free market may fail to provide these goods efficiently, as individuals may not be willing to pay for something they cannot be excluded from using.

2) Merit Goods: Governments may provide goods that are considered merit goods, which are goods that society believes everyone should have access to. Examples include food, housing, or medical care. By providing these goods, governments aim to ensure equal access and prevent inequality.

3) Positive Externalities: There are goods that have strong positive externalities, meaning that their consumption benefits society as a whole. Basic education or public works of art are examples of such goods. The free market may not take into account these external benefits, and governments intervene to ensure their provision.

4) Cost Recovery Difficulty: In some cases, private firms may find it challenging to recover the costs of developing certain goods. Basic medical research, for instance, involves high costs and long-term investments that may not be profitable for private firms. Governments may step in to fund such research to promote overall societal well-being.

5) Essential Services: Certain goods and services, such as police protection or the criminal justice system, are essential for the proper functioning of society. Governments provide these to ensure public safety and uphold the rule of law, as relying solely on the free market for these services may lead to inequities or inadequate provision.

6) Common Resources: Some goods, like national parks or other natural resources, are considered to belong to society as a whole. Governments manage and provide access to these resources to ensure their sustainable use and enjoyment for everyone.

7) Traditional Provision: There may be certain goods or services that governments have traditionally provided, and society expects them to continue doing so. Examples include tours of historical sites like the White House or public celebrations like fireworks on the 4th of July.

By understanding these reasons, we can appreciate why governments play a role in providing certain goods instead of relying solely on the free market.