When I began to research this topic, I was surprised—perhaps stunned is a better word— that the Roman Catholic Church has not denounced the whole idea long before now.
They have not! The Catholic Encyclopedia still defends the doctrine as accurate.
The practice, they say, is salutary. "Salutary" means "producing a beneficial effect". Thus, the doctrine, they say, is a good one. It is only the abuses that were a problem.
Here the Catholic Encyclopedia tells us that the only problem with indulgences is that certain clergymen used it for "pecuniary" or monetary gain. Except for these rogue clergymen, the belief that the leftover good works of the saints can be applied to others is regarded as "salutary."
So exactly how does the Roman Catholic Church describe indulgences? (You can read their descriptions yourself in the Catholic Catechism, paragraphs 1471-1479.)
There are two ideas involved in Roman Catholic teaching on indulgences:
Purgatory, at least, has some historical basis. I am unable to furnish any source from the pre-Nicene (before the Council of Nicea) Christians or from the Scriptures to explain the origin of indulgences.
The idea behind superabundant merits is that Christ and the saints did so many good works that they don't need them all. The merit they have obtained with God that is beyond their need can be transferred to others.
The Catholic Encyclopedia says:
Protestants greatly object to this idea as a form of works salvation (besides the issue of the sinlessness of Mary). Personally, I agree that works play a role in going to heaven, but this idea of transferring someone's good works to someone else has no basis that I can find in Scripture or early Christian history. Scripture talks about the righteousness of Christ being applied to those who repent and follow him, but because of faith, not because of charitable giving.
Further, if "the satisfaction of Christ infinite," and it "constitutes an inexhaustible fund," then what need do we have of the "virtues, penances, and sufferings" of the "saints"? Why are we trying to add to infinity?
In the early 16th century, indulgences were being used by the Roman Catholic Church to raise funds for the building of St. Peter's Basilica. Johann Tetzel, a German monk, was particularly adept at raising funds in this manner. To this day, the Roman Catholic Church condemns some of the promises Tetzel made (mostly concerning promising forgiveness without repentance), but they defend indulgences as an appropriate reward for charitable giving, including giving to "the building of churches."
Martin Luther did not agree. If the Roman Catholic Church could really remove the suffering from purgatory, he said, then they ought to do it immediately and empty purgatory for free (Thesis 82). Selling forgiveness for money seemed awful to him.
Speaking of history, where did this doctrine come from?
Finding the history of this practice is very difficult. As the Catholic Encyclopedia points out, the word originally meant a kindness or favor.
Thus, during the Middle Ages, when pilgrimages were common and looked upon with favor, various Church authorities can be quoted as saying that indulgences were given in return for pilgrimages. In other words, the Church told people that if they went on a pilgrimage their sins would be forgiven.
However, just because a Church authority said that sins could be forgiven in exchange for a pilgrimage doesn't mean that they believed in the doctrine of superabundant merits of the saints.
So what we're tracking is the change in the meaning of the word indulgence, and that's much harder to track than just finding out when the word began to be used.
I believe it should suffice to say that during the Middle Ages the Church, at least in Europe, had reached such a level of superstition that all sorts of religious activities—like pilgrimages and obtaining relics—were seen as having the power to forgive sins.