If the souls in purgatory are destined for heaven, why do we pray for them? Does the church teach that we should do this?
There is Scriptural evidence that our prayers are beneficial to those in purgatory. Judas Maccabeus “made atonement for the dead, that they might be delivered from their sin” (2 Macc 12:46). (See also 1 Cor 15:21-23, 2 Tim 1:16-18.) Whatever benefit is derived from our prayers however, we know that these souls cannot enter heaven until their purification is complete: “nothing unclean shall enter [heaven]” (Rev 21:27).
The Catechism of the Catholic Church teaches, “From the beginning the Church has honored the memory of the dead and offered prayers in suffrage for them, above all the Eucharistic sacrifice, so that, thus purified, they may attain the beatific vision of God. The Church also commends almsgiving, indulgences, and works of penance undertaken on behalf of the dead: Let us help and commemorate them. If Job’s sons were purified by their father’s sacrifice, why would we doubt that our offerings for the dead bring them some consolation? Let us not hesitate to help those who have died and to offer our prayers for them” (CCC 1032).