If there were no offspring, the Church could claim a priest's estate after his death.
Offloading excess sons into the church was also a useful ploy in those countries where primogeniture (inheritance by the firstborn son) wasn't the cultural norm. Assuming shared inheritance, a family's power and wealth is much easier to transmit down the generations if you can shift some of the potential inheritors into celibacy and avowed (if not necessarily practised) poverty. Daughters might be treated the same way to avoid dowry payments.
It was a slick system, and it only really began to break down in the last third of the nineteenth century courtesy of expanded suffrage and agricultural depression.