It is a holy and pious thought to pray for the dead (2 Mc 12:44-45). Because those in heaven or in hell don't benefit from our prayers, this implies that not everyone immediately goes to heaven or hell after they die. Therefore, when we pray for the dead, we must be praying for people in some other place, usually called purgatory (Catechism, 1031). It is a place of purging and purification (see 1 Cor 3:15).
In the New Testament, the Lord suggests the existence of some place other than heaven or hell. Jesus went to "preach to the spirits in prison," who "had disobeyed as long ago as Noah's day" (1 Pt 3:19, 20; see also 1 Pt 4:6). These passages may refer to a place after death other than heaven or hell, but we don't know if this place still exists.
Paul spoke of the Corinthians' practice of being baptized on behalf of the dead (1 Cor 15:29). The most likely translation of this passage implies there is some place other than heaven or hell.
Jesus taught that the sin of blasphemy against the Holy Spirit would not be forgiven in this age or in the age to come (Mt 12:32). Does this suggest that some sins can be forgiven after death? If so, there must be a place after death other than heaven or hell.
We know from early Christian art that the Church of New Testament times prayed for the dead. We should do likewise, for it is a holy and pious thought to pray for the dead and an act of faith in the resurrection of the dead.