The Catechism of the Catholic Church defines purgatory as a “purification, so as to achieve the holiness necessary to enter the joy of heaven,” which is experienced by those “who die in God’s grace and friendship, but still imperfectly purified” (CCC 1030).
The purification is necessary because nothing unclean will enter the presence of God in heaven and, while we may die with our mortal sins forgiven, there can still be many impurities in us, specifically venial sins and the temporal punishment due to sins already forgiven.
While the word purgatory is not found in the Bible, belief in the concept existed in the early church as evidenced in the catacombs where Christians during the persecutions of the first three centuries recorded prayers for the dead. Some of the earliest Christian writings outside the New Testament also refer to the Christian practice of praying for the dead.
Such prayers would have been offered only if Christians believed in purgatory, even if they did not use that name for it. In fact, the general custom of praying for the dead dates as far back as 2 Maccabees 12:42-46, which was written around 150 years before Christ. (7:31)