Indulgences are a part of the Roman Catholic sacrament of penance. This is a fairly complicated theological topic, but the basic premise is that a priest may absolve someone from the guilt of their sins if they are willing to confess, but in order to completely wipe the slate clean the sinner must pay some form of restitution to God. This can be in the form of penance performed on Earth (such as fasting), or time served in Purgatory. An indulgence is basically a special boon granted by the church that either lessens this debt that a sinner owes to God (partial indulgence) or completely removes the debt (plenary indulgence).
The ideas behind indulgences—paying penance for sins and the ability of clergy or martyrs to lessen that penance—can be traced back to the early church. But the actual practice of granting indulgences is connected to belief in Purgatory, which became widespread starting in the 11th Century. Pope Urban II was the first to grant indulgences, making announcements in 1089 and 1095 that participants of the Spanish Reconquista or the First Crusade would be given full remission of their sins. Indulgences were intimately connected with the Crusades, with preachers of indulgences all over Europe utilizing this system to encourage recruitment and financing of the wars. Christians unable to undergo pilgrimages to Jerusalem or unfit to participate in the Crusades were encouraged to contribute financial donations to the church. Pope Innocent III especially encouraged the commercialization of indulgences to finance his crusading projects. Indulgences were also used to finance the building of churches, roads, bridges, hospitals, and other ecclesiastical or social programs all across Christendom.
The initial purpose of giving alms as a form of penance was supported within the church as it was part of the extended process of confession and absolution of sins; it wasn’t until 1476 when Pope Sixtus IV officially allowed the granting of indulgences for dead relatives in Purgatory that theological problems arose. These souls in Purgatory were getting the benefits of the indulgence without the need of a confession or repentance. This threatened the entire penance system and led to an increase in corruption and eventually influenced the 95 Theses and the Protestant Reformation.