A free market can fail to allocate resources at the right price and at the socially optimal output. Market failure arises from: over-production of demerit goods, under-provision of public and merit goods, negative externalities of production and consumption, information failure and asymmetric information, and abuse of monopoly power by dominant firms. Governments intervene to correct these failures and to achieve equity.
Public goods are non-rivalrous and non-excludable, so people can free ride and private firms cannot charge for them profitably. The market provides none (or too few), so the government provides them directly (defence, street lighting, flood defences, lighthouses) and funds them through taxation.
Analysis chain (AO2): Public goods are non-excludable → free-rider problem → firms cannot charge → no market provision → government provides the good, financed by taxation.