Going to confession recently is a condition for gaining any indulgence for oneself. You can gain an indulgence for someone deceased only if that person was truly sorry for his or her sins.
Doesn’t going to confession wipe out the sins confessed? A sin can be forgiven and yet still continue to have a harmful effect. That’s what the “temporal punishment due to sin” idea addresses.
Once we commit a sin, that sin has a life of its own—no longer totally under our control. If I knew you and told a lie about you, I might later repent of that lie and be forgiven in confession.
Unfortunately, that lie would have a life of its own. Even if I went back and told the truth to each person to whom I told that lie, I could never guarantee that my efforts would undo all the damage caused by this lie. The truth may never reach everyone who heard the lie!
Or, if I put a baseball through your window, I may be very sorry and you may forgive me—but you still have a broken window!
There is always damage between the time I sin and the time I repent and begin repairing the damage. My sin may have encouraged others—and may still do so even after I repent.
All this is not to make people feel crushed by guilt but to be realistic: My sins, your sins, anybody’s sins have a life of their own, a life which does not instantly cease when a sinner repents and is forgiven by God.
The teaching about purgatory recognizes that a person may not be ready to meet God and enjoy the beatific vision at the moment of death. Some purification may yet be needed. This is why for centuries the Christian community has prayed and continues to pray for its deceased members.