Purgatory is a place of spiritual cleansing. Anyone who dies in the grace of God but is not free from all temporal punishment due to sins cannot go to Heaven at once. Those who still have to do penance for their sins go first to Purgatory.
“But nothing unclean shall enter it [Heaven], nor any one who practices abomination or falsehood, but only those who are written in the Lamb’s book of life” (Revelation 21:27).
Purification is a matter of purging the soul and of preparing it for the full perfection of the supernatural life, which it already possesses. The soul must complete what was lacking in its fidelity and honor to God on earth. The soul’s final turning to God happens through suffering. The real element which effects this cleansing and fulfillment of the soul in Purgatory is its living love of God, which it possessed on leaving this life.
The soul in Purgatory is animated by an ardent desire for absolute holiness in order to please God. Purgatory will continue to exist until the whole world has been judged on the Last Day. After this final judgment, there will be nothing left but Heaven and Hell.