There is no one answer because some agencies are more efficient than others.
For example, Medicare is much more efficient in processing and paying medical claims than private insurance companies are at the same task. Medicare devotes just 1.4% of expenditures for administrative costs (a more skeptical analysis that used a broader definition of administrative costs came up with 5.2%), with the rest of its funds going towards payment of claims, while private health insurers devote 11%-20% of their expenditures to administrative costs, leaving a smaller share of its resources to pay claims. See also here ("Medicare outperforms private sector plans in terms of patients' satisfaction with quality of care, access to care, and overall insurance ratings.") and here (health care spending goes down while service utilization is unchanged when an average person transitions from private health insurance to Medicare). You can argue that Medicare is able to do that, in part, because by having a policy of paying the prevailing insurance company negotiated price of any provider that it is free riding on costs incurred by private insurance companies to negotiate lower prices with providers, but certainly, Medicare dispenses with significant expenditures associated with advertising and executive compensation that private insurance companies must pay that it need not. Less obviously, Medicare claims processing is more efficient because every medical provider processes lots of Medicare clams and learns how to do it correctly, while a medical provider may process claims from a smaller health insurer only sporadically.
Similarly, Social Security is more efficient in its administration of benefits dispersal than than almost any private sector retirement plan (which average 1.5% to 1.8% administrative fees) in existence. Annuities, the closest private sector analogy to Social Security, have particular high administrative fees (on average 2.3%).
Social Security may not maximize investment return (not so much because it couldn't, lots of states have public employees retirement systems that do so at a quite low administrative cost, as because it is mandated by law to invest in Treasury securities and nothing else, the safest investment in existence often operationally treated by economists as the risk free rate of return), but this is, in part, to provide maximum security when markets fail (Social Security was devised after the collapse of financial markets that led to the Great Depression left many people who had saved diligently all their lives penniless.) Social security isn't just an investment, it is insurance against other investments turning out poorly when bear markets destroy investment wealth.
The U.S. Department of Education took over direct servicing of student loans because that turned out to be more efficient than what the private sector was doing. As Wikipedia explains, the system was put in place, while "[g]uaranteed loans—loans originated and funded by private lenders but guaranteed by the government—were eliminated because of a perception that they benefited private student loan companies at the expense of taxpayers, but did not help reduce costs for students."
In general, government agencies can be very efficient at handling large volumes of administrative paperwork involving large numbers of small individual cases as the examples above illustrate, in part, due to economies of scale.
Also, in some cases, it is hard to compare because there is no close private sector counterpart. One could say that the U.S. Department of Defense is very inefficient (and no one seriously disputes that there are many ways it could be made significantly more efficient even though the magnitude of potential savings varies greatly), but there is no private sector counterpart running the largest military force in the world by many measures. One could try to compare, for example, the efficiency of military defense procurement projects done by private companies under contract with the government to private sector manufacturing enterprises of other kinds, like automobile manufacturers. But, private sector manufacturing is arguably under pressure to achieve very different objectives - the best possible outcome at an affordable price, rather than the best possible outcome at any price because failing means the end of civilization as we know it.
There are also areas where there is considerable private sector competition with public sector institutions, providing a means of comparison, but the public sector institutions aren't notably better or worse in efficiency than the private sector counterparts and both are equally inefficient. There is a good case to be made that this is true of schools, colleges, universities, and hospitals ("5 studies reveal that public and not-for-profit hospitals are more efficient than those in private ownership. One study concludes the opposite, and 2 could not demonstrate any significant differences between the different hospital ownerships."). (Although per student or per degree costs of community college programs in the public sector are much lower for better outcomes than their private sector counterparts despite low rates of government subsidies per student than any other form of public higher education).
There is likewise no compelling evidence that private prisons are run more efficiently, controlling for the makeup of the prisoners supervised, than public prisons.
Similarly, there are private sector businesses that are very inefficient and dysfunctional, often because they don't face much competition. The cable company is a private company, but has a monopoly franchise in any given place for an extended time period (because it is a "natural monopoly", or at least used to be one), and unsurprisingly it has poor customer service and lots of inefficiencies and mismanagement that is allowed to persist. In addition to utilities, companies with patents (e.g. drug companies) can sometimes be inefficient because they have government monopolies. Indeed, one of the justifications for patents is that they are necessary to allow something inefficient (research and development that will often not pan out) to be conducted.
Certainly, this isn't to say that there are no areas where the private sector does not get the job done better and cheaper than the public sector. But, even in those cases, this isn't universal. Some countries, like France and Sweden, do a particularly good job of public administration (anecdotal evidence here). Indeed, the most prestigious university in all of France is a school for public administrators. Other countries, like the U.S., are worse at public administration, such as Italy.
But, as these examples illustrate, there is no one compelling reason.
Probably the most powerful reason that the private sector is sometimes better than the public sector comes from countries with many state-owned enterprises. Comparisons in those cases indicate that the single greatest factor is that money-losing private businesses promptly go out of business or are reorganized in bankruptcy, while deficits in state-owned enterprises are often subsidized and keeping them in business for a long time. (Also, some state owned enterprises are intentionally inefficient as a means of providing political patronage).
The fact that government institutions don't automatically shut down when they cease to be profitable as currently organized is sometimes a feature, rather than a flaw, however. Half of all private businesses fail within their first five years. Government institutions are frequently established to provide services that cannot for practical reasons, or should not, for moral reasons, be discontinued.
For example, while in Japan and the Netherlands (both places where space is at a premium), public sensibilities are O.K. with tossing human remains in a dumpster if the surviving family fails to pay an annual cemetery bill, in the U.S., cemetery administration is often vested in a government because the time horizon over which we expect that it will continue to need to be maintained is infinite.
Similarly, you don't want to nuclear waste disposal facility to just shut down and have its employees all laid off because fees from new waste deposits no longer cover its operating costs, even if the problem arose because an incompetent nuclear waste facility administrator a decade ago underestimated how long it would cost to keep the facility open in what was supposed to be a self-supporting enterprise.
We want water and sewer systems, the military, law enforcement agencies, historical archives, the courts, real estate record keeping, a school for the deaf, and the like to continue indefinitely, even if this eliminates one of the easier ways to control inefficiency, by shutting down inefficient institutions entirely. Government ownership is often an alternative to utility regulation for natural monopolies that must also endure in the long run.
When shutting down inefficient institutions entirely isn't an option, you look for alternative solutions like developing strong audit and oversight institutions with the power to bring about change when an institution operates inefficiently.
Amtrak exists, for better or worse, because somebody in government decided in 1971 that the United States needed at least one passenger rail company when all of them were going bankrupt and all of the infrastructure involved in once private passenger rail system was at risk of going to waste. There are legitimate reasons to say that maybe the United States doesn't actually need a slow speed passenger rail system using 1960s technology. But, once somebody has decided that the service must be provided even though it doesn't make economic sense to do so, it is impossible to run that service in an efficient manner.