Christians get into Heaven on the basis of their faith in Jesus Christ. This inconvenient fact left Catholic priests of the Middle Ages in a quandary. If you can't threaten congreants with punishment in the afterlife, how are you going to control them? So the priests invented sacraments (see also Purgatory).
Thanks to sacraments, priests could imperil the souls of lay people, even kings, by withholding sacraments from them. Lay people became spiritually dependent on the church hierarchy, which meant that the clergy gained power over them.
The priests even invented the sacrament of confession and penance, in which the lay person imperils their own soul if they don't tell a priest all their sins. Suppose it might have been politically useful for the medieval clergy to know everyone's dirty secrets?
Here's another sacrament they came up with: holy orders. In other words, becoming a priest was a sacred, miraculous act that altered one's status with God. I bet it wasn't too hard for priests to accept the idea that they were special. And since only a priest can conduct a sacrament, the sacrament was a way to keep the club "invitation-only."
But are the sacraments really there to serve the clergy? Just look at what gets you automatically excommunicated. Among other affronts, physically attacking a bishop gets you excommunicated. That was a handy ruling in the rough-and-tumble Middle Ages. Also, if a married woman falsely accuses a priest of propositioning her during confession, that's automatically excommunicable. Can't you just see the priests solemnly agreeing that it's just terrible when those uppity women "falsely" report such propositions.
The power that clergy gained over the laity (through sacraments, etc.) is seen at work today. For example, for years Catholic clergy were able to coerce silence from victims of clerical child molesters and from their families. More recently, some bishops have called for priests to deny communion to politicians that don't toe their line.
Catholic Doublespeak: irony and doctrine