Before we enter into full communion with God,the sin which stains, behaviors which have bent our consciousness, must be eliminated and every imperfection in our soul must be corrected. It is NOT that we are not forgiven, we are, it is the imperfect LEARNED behaviors which must be erased.
The biggest example I can give is that most people feel UNWORTHY of GOD'S Divine Love. It is the misunderstanding that we MUST earn GOD'S love. It is these things which must be purified from the Soul before entering Heaven.
We ARE forgiven when we first have FAITH in JESUS CHRIST and HIS sacrifice on the Cross for ALL of our sins. Purgatory is not for forgiveness but for the removal of faulty thinking and understanding of what exactly constitutes GOD'S Love.
We can not earn GOD'S love, nor can we increase GOD'S love for us by works and deeds. GOD'S love is perfect from the beginning, it lacks nothing and needs nothing.
At the General Audience of Wednesday, 4 August 1999, following his catecheses on heaven and hell, the Holy Father reflected on Purgatory. He explained that physical integrity is necessary to enter into perfect communion with God therefore "the term purgatory does not indicate a place, but a condition of existence", where Christ "removes ... the remnants of imperfection".
1. As we have seen in the previous two catecheses, on the basis of the definitive option for or against God, the human being finds he faces one of these alternatives: either to live with the Lord in eternal beatitude, or to remain far from his presence.
For those who find themselves in a condition of being open to God, but still imperfectly, the journey towards full beatitude requires a purification, which the faith of the Church illustrates in the doctrine of "Purgatory" (cf. Catechism of the Catholic Church, n. 1030-1032).
2. In Sacred Scripture, we can grasp certain elements that help us to understand the meaning of this doctrine, even if it is not formally described. They express the belief that we cannot approach God without undergoing some kind of purification.
According to Old Testament religious law, what is destined for God must be perfect. As a result, physical integrity is also specifically required for the realities which come into contact with God at the sacrificial level such as, for example, sacrificial animals (cf. Lv 22: 22) or at the institutional level, as in the case of priests or ministers of worship (cf. Lv 21: 17-23).
Total dedication to the God of the Covenant, along the lines of the great teachings found in Deuteronomy (cf. 6: 5), and which must correspond to this physical integrity, is required of individuals and society as a whole (cf. 1 Kgs 8: 61). It is a matter of loving God with all one's being, with purity of heart and the witness of deeds (cf. ibid., 10: 12f.)
The need for integrity obviously becomes necessary after death, for entering into perfect and complete communion with God. Those who do not possess this integrity must undergo purification. This is suggested by a text of St Paul.
The Apostle speaks of the value of each person's work which will be revealed on the day of judgement and says: "If the work which any man has built on the foundation [which is Christ] survives, he will receive a reward. If any man's work is burned up, he will suffer loss, though he himself will be saved, but only as through fire" (1 Cor 3: 14-15).
3. At times, to reach a state of perfect integrity a person's intercession or mediation is needed. For example, Moses obtains pardon for the people with a prayer in which he recalls the saving work done by God in the past, and prays for God's fidelity to the oath made to his ancestors (cf. Ex 32: 30, 11-13).
The figure of the Servant of the Lord, outlined in the Book of Isaiah, is also portrayed by his role of intercession and expiation for many; at the end of his suffering he "will see the light" and "will justify many", bearing their iniquities (cf. Is 52: 13-53, 12, especially vv. 53: 11).
Psalm 51 can be considered, according to the perspective of the Old Testament, as a synthesis of the process of reintegration: the sinner confesses and recognizes his guilt (v. 3), asking insistently to be purified or "cleansed" (vv. 2, 9, 10, 17) so as to proclaim the divine praise (v. 15).
4. In the New Testament Christ is presented as the intercessor who assumes the functions of high priest on the day of expiation (cf. Heb 5: 7; 7: 25). But in him the priesthood is presented in a new and definitive form. He enters the heavenly shrine once and for all, to intercede with God on our behalf (cf. Heb 9: 23-26, especially, v. 24). He is both priest and "victim of expiation" for the sins of the whole world (cf. 1 Jn 2: 2).
Jesus, as the great intercessor who atones for us, will fully reveal himself at the end of our life when he will express himself with the offer of mercy, but also with the inevitable judgement for those who refuse the Father's love and forgiveness.
This offer of mercy does not exclude the duty to present ourselves to God, pure and whole, rich in that love which Paul calls a "[bond] of perfect harmony" (Col 3: 14).
Moreover, we are invited to "cleanse ourselves from every defilement of body and spirit" (2 Cor 7: 1; cf. 1 Jn 3: 3), because the encounter with God requires absolute purity.
Every trace of attachment to evil must be eliminated, every imperfection of the soul corrected. Purification must be complete, and indeed this is precisely what is meant by the Church's teaching on purgatory. The term does not indicate a place, but a condition of existence.
Those who, after death, exist in a state of purification, are already in the love of Christ who removes from them the remnants of imperfection (cf. Ecumenical Council of Florence, Decretum pro Graecis: DS 1304; Ecumenical Council of Trent, Decretum de iustificatione: DS 1580; Decretum de purgatorio: DS 1820).
It is necessary to explain that the state of purification is not a prolungation of the earthly condition, almost as if after death one were given another possibility to change one's destiny. The Church's teaching in this regard is unequivocal and was reaffirmed by the Second Vatican Council which teaches: "Since we know neither the day nor the hour, we should follow the advice of the Lord and watch constantly so that, when the single course of our earthly life is completed (cf. Heb 9: 27), we may merit to enter with him into the marriage feast and be numbered among the blessed, and not, like the wicked and slothful servants, be ordered to depart into the eternal fire, into the outer darkness where "men will weep and gnash their teeth' (Mt 22: 13 and 25: 30)" (Lumen gentium, n. 48).
6. One last important aspect which the Church's tradition has always pointed out should be reproposed today: the dimension of "communio". Those, in fact, who find themselves in the state of purification are united both with the blessed who already enjoy the fullness of eternal life, and with us on this earth on our way towards the Father's house (cf. CCC, n. 1032).
Just as in their earthly life believers are united in the one Mystical Body, so after death those who live in a state of purification experience the same ecclesial solidarity which works through prayer, prayers for suffrage and love for their other brothers and sisters in the faith. Purification is lived in the essential bond created between those who live in this world and those who enjoy eternal beatitude.
some info taken from: https://www.ewtn.com/library/PAPALDOC/JP2HEAVN.HTM