I'll describe in turn five potential explainations:
- Risk aversion interacting with the tax code
- Is this true when we control for worker attributes?
- Lack of incentives for cost control
- Solving turnover, training and other HR problems
- Political economy: unions and politicians
Risk aversion interacting with the tax code
I've heard it argued (but not empirically substantiated) that because government positions generally offer very low risk of job loss they attract risk adverse people.
All other things equal, relatively risk adverse people like relatively generous insurance and have a greater precautionary savings motive against negative shocks. Because retirement savings, health insurance, and to a lesser extent, life insurance have tax advantages when purchased through the employer, this risk aversion would interact with the tax advantage to induce a high level of retirement savings, health, and life insurance. Disability insurance is not tax advantaged, but employer-run plans do help solve some of the adverse selection problems associated with stand alone disability plans and so they too have an incentive to be employer provided and more generous in government positions for similar reasons.
Is this true when we control for worker attributes?
That all said, I'll echo @rocinante's point that among some sub-populations of workers, it isn't clear that government benefits are particularly extensive. My reading of the Are government employees overpaid? literature is that highly educated or skilled government workers do not typically appear overpaid (in a Mincer regression residual sense) relative to their private sector counterparts, and this includes measures of income and benefits. And elite financial and IT firms are often famous for their lavish benefits of meals, profit sharing, and low cost health care. However, part of the story there is that wages are higher in those fields and benefits are generally increasing in wages (if only because so are the tax advantages). It may be surprising to hear this but the average education and age of a public sector worker is substantially higher than in the private sector, explaining some of the higher wages and higher benefits.
Lack of incentives for cost control
So while it may well be true that, as @kbelder says, public sector employers have less of an incentive to hold down benefits, they have less of an incentive to hold down wages too, at least in conventional wisdom government employee benefits are more different from private sector benefits than the wages are, so that leaves us with a remaining puzzle beyond poor cost containment incentives.
Solving turnover, training and other HR problems
@rocinante's point about turnover is also a good one. We can think of the employee-employer relation as a sort of investment that pays returns while employment persists. Any situation where the initial employer investment (e.g., in training, background checks, customized equipment) is large relative to the immediate payout is one in which the employer is going to want to incentivise the employee to stick around until that investment is repaid. Pensions, which back-load compensation have a powerful incentivizing effect towards retaining staff under these circumstances.
Similarly, when positions require idiosyncratic human capital (extensive expertise and training not useful for other employers), this makes the employee strongly value continuing the employee relationship, and if government employers particularly require this sort of expertise (say maintaining ICBMs) then employment protection benefits may be another efficient way to attract staff without paying higher wages.
Political economy: unions and politicians
Finally, two more reasons from a political economy angle. First, unions may not just get better benefits because they have more power and influence but also because the people who run unions wish greater power and influence. To those ends, higher wages give them less than retirement and benefits programs which require wealth and staffing to be run by the union. Second, benefits, particularly defined benefit pensions, can be opaque in their true costs. Since politicians have to answer in elections to the public, HR strategies that please government employees (like high defined benefit pensions) but appear to be low cost to the public (again like high defined benefit pensions) therefore are relatively attractive to the politicians that administer the government.