"There is nothing special about markets per se - they can perform very badly in some circumstances. It is competitive markets that are magic, though even then we have to remember that markets have no concern whatsoever with equity, only efficiency, and sometimes equity can be an overriding concern.
In order to work their magical efficiency, markets need very special conditions to be present. There must be full information available to all participants. Product quality, locations and prices of alternative suppliers, every relevant piece of information must be known... Information problems are common and they can cause substantial departures from the perfectly competitive, ideal outcome.
There also must be numerous buyers and sellers, enough so that no single buyer or seller's decisions can affect the market price... Whenever there are a small number of participants on either side of the market - suppliers or demanders - this is potentially problematic.
In order for markets to work their magic, the product must be homogeneous. That is, the product or input to production sold by all firms in the market must be perfectly substitutable so that as far as the buyer is concerned, one is as good as the other... In order for markets to work their magic there must be free entry and exit... Whenever barriers exist in markets that prevent free movement into and out of the marketplace or between firms within a market (on either side - there are sometimes barriers to purchasing as well), markets will underperform.
In order for markets to work their magic, there can be no externalities, no public goods, no false market signals, no moral hazard, no principle agent problems, and, importantly, property rights must be well-defined (and I probably missed a few). In general, the incentives that the market provides must be consistent with perfect competition, or nearly so in practical applications...
There is nothing inherent in markets that guarantees a desirable outcome. A market can be a monopoly, a market can be perfectly competitive, a market can be lots of things. Markets with bad incentives produce bad outcomes, markets with good incentives do better."
And this really is very important, especially in a world where privatization is often seen as the panacea for many public sector problems,
"Markets don't work just because we get out of the way. When government contracts are moved to the private sector without ensuring the proper incentives are in place, there will be problems - waste, inefficiency, higher prices than needed, etc. There is nothing special about markets that guarantees that managers or owners of companies will have an incentive to use public funds in a way that maximizes the public rather than their own personal interests. It is only when market incentives direct choices to coincide with the public interest that the two sets of interests are aligned.
If there is no competition, or insufficient competition in the provision of government services by private sector firms, there is no reason to expect the market to deliver an efficient outcome, an outcome free of waste and inefficiency. Why would we think that giving a private sector firm a monopoly in the provision of a public service would yield an efficient outcome? If the projects are of sufficient scale, or require specialized knowledge so that only one or a few private sector firms are large enough or specialized enough to do the job, why would we expect an ideal outcome just because the private sector is involved? If cronyism limits the participants in the marketplace, why would we expect an outcome that maximizes the public interest?"
So, what is the test for government involvement?
"For government goods and services, when incentives consistent with a competitive outcome are present, we should get government out of the way and privatize, and there are lots of circumstances where this will be appropriate... When competitive conditions are not met but can be regulated, the regulations should be put in place and the private sector left to do its thing (e.g. mandating that sellers disclose problems with a house to prevent asymmetric information or mandating that government funded projects be subject to competitive bidding and monitoring to ensure contract terms are met)...
But rampant privatization based upon some misguided notion that markets are always best, privatization that does not proceed by first ensuring that market incentives are consistent with the public interest, doesn't do us any good... free does not mean the absence of government intervention, regulation, or oversight... even libertarians agree that governments must intervene to ensure basics like private property rights. Free means that the conditions for perfect competition are approximated as much as possible and sometimes that means the presence - rather than the absence - of government is required."