The Catholic Encyclopedia online notes:
Once it is admitted that Christ left the Church the power to forgive sins, the power of granting indulgences is logically inferred. Since the sacramental forgiveness of sin extends both to the guilt and to the eternal punishment, it plainly follows that the Church can also free the penitent from the lesser or temporal penalty. This becomes clearer, however, when we consider the amplitude of the power granted to Peter (Matthew 16:19): ‘I will give to thee the keys of the kingdom of heaven. And whatsoever thou shalt bind upon earth, it shall be bound also in heaven: and whatsoever thou shalt loose on earth, it shall be loosed also in heaven.’ (Cf. Matthew 18:18, where like power is conferred on all the Apostles.)
Indulgences are a remnant of early penitential practice when penances were publically performed. Mortal sin was punished by exclusion from the Eucharist, sometimes for years of penance, during which fasting and prayer were called for. The early Church withheld “absolution” (but not of guilt) until satisfaction was made. “Regarding the nature of this absolution given by the bishop, various opinions have been put forward. According to one view, it was the remission, not of guilt but of the temporal punishment; the guilt had already been remitted by the absolution which the penitent received in confession before he entered on the public penance.” Public penances for mortal sin could be severe. Penances were lessened for those who were ill or in danger of death. Among the forms of commutation of the penance were pilgrimages, especially to places like Jerusalem or Rome. It was the report of the ill treatment given these pilgrims by the Muslims that led to the Crusades. At the Council of Clermont in 1095 where the First Crusade was organized they provided: "Whoever, out of pure devotion and not for the purpose of gaining honor or money, shall go to Jerusalem to liberate the Church of God, let that journey be counted in lieu of all penance."
When individual confession became the rule, absolution was given immediately after confession (assuming the penitent was sorry for their sins and had a firm purpose of amendment) and lighter penances than those shown in the canons were assigned. Secret confession goes back to the time of the Apostles but even in the days of Pope Leo the Great (440-461) he declares an abuse, “contrary to the Apostolic rule" the reading out in public of a written statement of their sins drawn up by the faithful. Penance was said or done immediately after Confession. Indulgences were a form of penance. They could not forgive sins nor were they a substitute for true contrition. Rather, it was a remission of some or all of the punishment due from sins already forgiven granted by the Church to those who met all the conditions for the indulgence. It was based on the Church’s “treasury of grace” earned by Christ for living persons through absolution and for the dead, as a petition. The grace won by Christ is “God’s saving will in the fullness of love to individual human persons, which also includes purification and overcoming of the punishment due to sin.” This is why the preconditions always include personal, genuine repentance by the sinner and the restoration of the damaged order in so far as this is possible.
The Church showed concern for the misuses and abuses of indulgences. For example, Pope Boniface in 1382 condemned the practice of some religious who were claiming indulgences forgave sin and selling them for money. In 1420 the Archbishop of Canterbury was reprimanded for initiating an indulgence by Pope Martin V. In 1450 Cardinal Nicholas of Cusa, then Apostolate Legate to Germany, corrected those claiming that indulgences forgave sins. Pope Sixtus IV reserved judgment to the Holy See in cases previously delegated to the Holy See. By 1500 the papacy reserved for itself the right to grant indulgences because of abuses by bishops or priests. Nonetheless, the uneducated did not always make the distinctions between eternal punishment and temporal punishment and some comforted themselves by thinking they were buying their salvation thanks to abuses which found their way back into Church before the Reformation.
Initiated by Pope Julius II and revived by Pope Leo X, a plenary indulgence was offered to all those who confessed their sins, received the Eucharist, and contributed according to their means to construction costs of the new St. Peter’s (which is still in use today). Some papal indulgences were administered by local bishops. For example, the young and ambitious Archbishop Albert of Mainz and Magdeburg was one who decided to foster the sale of indulgences in his territories in an effort, in large part, to pay Rome for a dispensation permitting him to rule two dioceses. He enlisted the Dominicans to proclaim the indulgence, but some like Johan Tetzle did this, Luther alleged, in such a crude way it seemed like grace was for sale. Was the problem was the way they were administered by Tetzle and others? Yes, but perhaps Tetzle was not the villain Luther made him out to be. Recently historians say he received unmerited odium. For example, Luther in his 95 theses accuses him of using the jingle, “As soon as a coin in the coffer rings, the soul out of purgatory springs.” This goes back at least to 1482 and Teztle denies it. In fact, he wrote in his defense, A History of Auricular Confession and Indulgences. He went on to get his doctorate in theology but retired to a monastery in 1518, broken in spirit by what was probably unjust criticism. Luther himself wrote him “that the agitation was not that of his creation, but that the child had an entirely different father.” But Luther, nonetheless, falsely charged that Tetzle had preached impiously against the Virgin Mary.
Whether or not Tetzle was guilty is not as significant as the fact that the Church was not sufficiently guarding against abuses in indulgences to preclude Luther using this issue as a springboard for his revolution against the Catholic Church. Certainly the Church addressed this problem and many other needed reforms in the Council of Trent, when they ended all selling of indulgences. But a great irony is pointed out by Msgr. Patrick O’Hare in his book, Luther: The Facts About, when he notes:
What hypocrisy to roll up the white’s of one’s eyes in pretence of holy horror at the Catholic doctrine of indulgences, which is severity itself compared with their sweeping act of faith which alone suffices to wash all man’s sins away, and put him at once, without penance or purgatory, into the company of angels in Heaven.”
 “Indulgences,” Catholic Encyclopedia online.