When I was much younger, occasionally, when I would complain about the difficulty of a task I was given, I would be told by an adult that by enduring "Your time in Purgatory will be short."
From the Latin verb purgo ("to clean, cleanse"), the word "purgatory" starts to be used in the second half of the 12th century to refer to the need for imperfect souls to be cleansed in order to enter Heaven, and gives rise to the idea of a place where this happens. 2 Maccabees 12:46 says "It is therefore a holy and wholesome thought to pray for the dead, that they may be loosed from sins." This suggests that the souls of the dead need further purification that they did not receive in life.
The Second Council of Lyon in 1274 defined its teaching on Purgatory, though didn't state that it was a place:
Because if they die truly repentant in charity before they have made satisfaction by worthy fruits of penance for (sins) committed and omitted, their souls are cleansed after death by purgatorical or purifying punishments…. And to relieve punishments of this kind, the offerings of the living faithful are of advantage to these, namely, the sacrifices of Masses, prayers, alms, and other duties of piety, which have customarily been performed by the faithful for the other faithful according to the regulations of the Church. [line 856]
...and just so we cover all the bases about Heaven and Hell:
However, the souls of those who after having received holy baptism have incurred no stain of sin whatever, ... are received immediately into heaven. [line 857]
The souls of those who die in mortal sin or with original sin only, however, immediately descend to hell, yet to be punished with different punishments. [line 858]
The dogma of Purgatory was re-affirmed in the Councils of Florence (1443) and Trent (1545-63). People can die in a state of grace but their souls still need some cleansing, and their time in Purgatory could be shortened by the prayers of the living.
Dante of course dedicates a third of the Divine Comedy to Purgatorio, in which we find people constantly praying to work their way into Heaven. His Purgatory (and others) is described as a place of purification, not punishment. There are depictions, however, of Purgatory as a "mini Hell" where fire and torment is the cleansing method.
The Orthodox Church rejected the notion of a third location where the souls of the dead could go, but the need for purgation is still part of Orthodox theology. In this case, the imperfect soul goes to Hell, but the prayers of the living can help purify them so that they transition to Heaven. (This is the "punchline" to The Great Divorce by C.S.Lewis: anyone can leave the bleakness of Hell and travel to Heaven, but they have to be prepared to change internally and understand their imperfections.)
Now, about the Second Council of Lyon: a lot of events were connected to it, and it has cropped up before in this blog. I want to pull the separate threads together tomorrow.