If a person dies in a perfect state of grace without any stain of sin whatsoever on them, they would go directly to heaven (good luck to all of us on that). If a person dies with a mortal sin on their soul and is totally unrepentant upon their death, they go directly to hell. I know this isn’t a popular way of thinking today, but I have yet to see any valid teaching that says different.
So what about all that are somewhere in between? They have not chosen hell, yet they are not clean enough for heaven, because nothing unclean shall enter it. (Rev 21:27)
God is perfect in holiness:
Isaiah, chapter 6:3
And one called to another and said: “Holy, holy, holy is the LORD of hosts; the whole earth is full of his glory.”
Repetition was often used in some styles of biblical writing as a form of emphasis as opposed to using adjectives, such as “very” or “totally”.
We are called to be as holy as God Himself.
Matthew, chapter 5:48
You, therefore, must be perfect, as your heavenly Father is perfect
1 Peter, chapter 1:15-16 but as he who called you is holy, be holy yourselves in all your conduct;
since it is written, “You shall be holy, for I am holy.”
Without perfect holiness we will not be with God in heaven.
Hebrews, chapter 12:14
Strive for peace with all men, and for the holiness without which no one will see the Lord.
But nothing unclean shall enter it
The word “unclean” comes from the Greek word “koinon” which refers to a spiritual corruption. Even the propensity to sin is spiritually corrupt, or considered unclean, and must be purified before entering heaven.
Purgatory exists because of the mercy of God. If there were no purgatory, this would also likely mean no salvation for most people. However, God is most merciful indeed!
So basically Purgatory is a temporary state of purification for all imperfect saints. The souls of the just who have died in a state of grace, however have venial sins or “scars” on their soul from forgiven mortal sins. They are fully cleansed when they enter into the kingdom of God.