If you are praying for the soul of a particular person who has died and that person is already in heaven, your prayers won’t be wasted. God will apply your prayers to another soul in Purgatory, so it is always valuable to pray for the souls of those who have died, even if they are actually in heaven, because you will be helping another soul in Purgatory.
If the church has declared someone to be a saint: e.g. St Therese, you do not pray for them, but to them!
Purgatory stems from God’s Mercy.
If there were was no Purgatory, anyone who died with even a slight stain on their soul would go to hell. Purgatory is a place of purification. Make no mistake about it though, it is a place of great suffering. It is not like a waiting room, where there is air-conditioning, a water cooler, a vending machine with drinks, snacks and some magazines to read while you wait for your appointment. Having said all that, God does not want you to go to Purgatory and you don’t have to. God can give you all the graces that you need to go straight to heaven. You need to respond to them.