Foundational to the Roman Catholic doctrine of purgatory is their understanding of the double-effect of sin. Note carefully the following description taken from the Catholic Catechism:
"Grave sin deprives us of communion with God and therefore makes us incapable of eternal life, the privation of which is called the 'eternal punishment' of sin. On the other hand every sin, even venial, entails an unhealthy attachment to creatures, which must be purified either here on earth, or after death in the state called Purgatory. This purification [in purgatory] frees one from what is called the 'temporal punishment' of sin" (CC, 1472).
As for purgatory itself:
"All who die in God's grace and friendship, but still imperfectly purified, are indeed assured of their eternal salvation; but after death they undergo purification, so as to achieve the holiness necessary to enter the joy of heaven. The Church gives the name Purgatory to this final purification of the elect, which is entirely different from the punishment of the damned" (CC, 1030-31).
According to Peter Kreeft, purgatory "refines and purifies those who at the moment of death are neither good enough for an immediate heaven nor bad enough