What is the purpose of praying for the dead according to Catholicism?
Those on earth do not know with certainty whether one is in hell, purgatory, or heaven—unless the Church has canonized the faithfully departed as a saint, in which case one is certain he or she is in heaven. Thus, Catholics pray for departed souls in the case they might be in purgatory:
…the Catholic Church, instructed by the Holy Ghost, has, from the Sacred Writings and the ancient tradition of the Fathers, taught, in sacred Councils, and very recently in this œcumenical Synod [i.e., the Council of Trent], that there is a Purgatory, and that the souls there detained are helped by the suffrages [intercessions] of the faithful, but principally by the acceptable sacrifice of the altar…
Holy Mass and the prayers of the faithful help shorten the holy souls' time and sufferings in purgatory.
Catholics' prayers are of no avail for the damned souls, as those souls are damned for all eternity and can never enjoy the Beatific Vision: "Those (the rejected) will receive a perpetual punishment with the devil." (4th Lateran Council, 1215).
The Catholic Church believes that souls who die in the state of grace, yet still need to be purified from the temporal punishment due to sin are purified in Purgatory.
Catholic teaching regarding prayers of the dead is bound up inseparably with the doctrine of purgatory and the more general doctrine of the communion of the saints, which is an article of the Apostle's Creed.
The poor souls can do nothing for themselves. They can no longer merit or give satisfaction or receive the sacraments or gain indulgences. They can only accept and offer their own suffering of satispassion. Hence they have a special right to be aided by others. - Fr. Reginald Garrigou-Lagrange, OP.
Since the Holy Souls in purgatory cannot get aid from their own merits or prayers, they rely totally on the prayers of others to help shorten their stay in purgatory.
Nevertheless the souls in purgatory can still pray for those of the Church Militant.
"The Holy Souls in Purgatory are not able to pray for themselves or do anything at all to relieve their suffering: They rely on our prayers and efforts to help them. It is permissible to believe that they can pray for their benefactors. St. John Vianney said: "If one knew what we may obtain from God by the intercession of the Poor Souls, they would not be so much abandoned. Let us pray a great deal for them, they will pray for us." St. Theresa of Avila (Spain) said that she always obtained the favours, which she asked from God, through the intercession of the Poor Souls in Purgatory. We must help the Holy Souls in Purgatory."
There is also a pious tradition of celebrating Gregorian Masses of 30 consecutive days for a particular soul in purgatory. Pope St Gregory the Great (590-604) had 30 Masses said in order to aid the soul of the monk Justus, who was in need of prayers. Pope Gregory tells us in his Dialogues that the monk Justus, later appeared and announced that he had been freed from purgatory at the conclusion of the 30th Mass!