It is not directly referenced by name, but there are multiple verses which teach about Purgatory. Let’s start with the basics. First, nothing unclean shall enter Heaven.
Rev 21:25 During the day its gates will never be shut, and there will be no night there. 26 The treasure and wealth of the nations will be brought there, 27 **but nothing unclean will enter it, **nor any[one] who does abominable things or tells lies. Only those will enter whose names are written in the Lamb’s book of life.
And lets ask the question, is there a place, other than Heaven, earth, and hell? The Bible says yes.
Jesus teaches about the Bossom of Abraham (which is obviously not Heaven, not earth, and not hell)
Luke 16:22 When the poor man died, he was carried away by angels to the bosom of Abraham. The rich man also died and was buried, 23 and from the netherworld, where he was in torment, he raised his eyes and saw Abraham far off and Lazarus at his side.
In Revelation is notes that Death and Hades will be thrown into hell. Hades can’t be hell since it is being thrown into hell. It’s not Heaven obviously, and not earth.
Rev 20:13 The sea gave up its dead; then Death and Hades gave up their dead. All the dead were judged according to their deeds. 14** Then Death and Hades were thrown into the pool of fire. (This pool of fire is the second death.) **15 Anyone whose name was not found written in the book of life was thrown into the pool of fire.
And St. Peter teaches that during Holy Saturday, Jesus went to preach to the souls of those who died before His time to offer them salvation. Obviously Jesus is neither on earth, hell or in Heaven.
1 Pet 3:18 For Christ also suffered for sins once, the righteous for the sake of the unrighteous, that he might lead you to God. Put to death in the flesh, he was brought to life in the spiritg 19 In it he also went to preach to the spirits in prison,
There are more verses, but I think this is enough to establish conclusively that there is a place other than Heaven, earth and hell.
So now we have the idea of paying for sins that are forgiven. Are there passages that describe this? Indeed there are. Take the example of King David, who sinned greatly by committing adultery with Bathsheba, and then sending her husband into the front of battle to have him killed to hide his sin. The prophet Nathan confronts David with his sin, and David confesses to Nathan his sin. The sin is forgiven, and yet, there is punishment still due for the sin.
2 Sam 12:13 Then David said to Nathan, “I have sinned against the LORD.” Nathan answered David: “For his part,** the LORD has removed your sin**. You shall not die, 14 but since you have utterly spurned the LORD by this deed, the child born to you will surely die.”
Likewise, Paul taught that if we build up works other than works of Christ, we will suffer great loss, but still be saved (if we confess the sins).
1 Cor 3:10 According to the grace of God given to me, like a wise master builder I laid a foundation, and another is building upon it. But each one must be careful how he builds upon it, 11 for no one can lay a foundation other than the one that is there, namely, Jesus Christ. 12 If anyone builds on this foundation with gold, silver, precious stones, wood, hay, or straw, 13 the work of each will come to light, for the Day will disclose it. It will be revealed with fire, and the fire [itself] will test the quality of each one’s work. 14 If the work stands that someone built upon the foundation, that person will receive a wage. 15 But if someone’s work is burned up, that one will suffer loss; the person will be saved, but only as through fire.
So the person will be saved, but they have to suffer loss. Now remembering our first point, that nothing unclean will enter Heaven, and that there can still be punishment due to sin, and attachment to sin can remain, how is this sin, attachment to sin, removed and how is the punishment completed? We don’t know the exact manner that it works, but the process of purification has been called by the Church Purgatory.
I hope that answers your question!