Any prayer or pious act applied to the souls in purgatory can be a way to pray for them. The most effective manner of praying is to have Masses offered for them or to apply the fruits of your own attendance at Mass. The Rosary, too, is a wonderful way to pray for them.
We pray for the souls in purgatory because they are undergoing the final purifications that are necessary for most of us after we die. This is because Scripture says of heaven: “nothing unclean will enter it” (Rv 21:27). Jesus also made a promise to each of us when he said, “So be perfect, just as your heavenly Father is perfect” (Mt 5:48).
Most of us realize that few leave this world as perfect or pure, even if they are in friendship with God and in a state of grace. Some final work must be done to take away any final attachments to sin, any rough edges, any sorrows, regrets or hurts. These things are surely disclosed when we appear before the judgment seat of Christ (see 2 Cor 5:10).
How this purification is done is mysterious, but Scripture gives two images, one consoling and the other more vigorous. The Book of Revelation supplies the consoling thought that, regarding the dead, Jesus “will wipe every tear from their eyes, and there shall be no more death or mourning, wailing or pain, [for] the old order has passed away” (Rv 21:4). The more vigorous text comes from St. Paul, who speaks of a fiery purgation the dead will pass through on the day of judgment: Each one’s work will become manifest, “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. If the work stands that someone built upon the foundation, that person will receive a wage. But if someone’s work is burned up, that one will suffer loss; the person will be saved, but only as through fire” (1 Cor 3:13-15).
So on account of this judgment and purification (that seems necessary and is taught), we pray for the dead that this process be swift and that they be in the full glory of heaven soon.
It is the instinct of the Church that our prayers help, which is an ancient practice, stretching back into the Old Testament (see 2 Mc 12:40-46). It is our wish to assist these souls and speed their purifications that may be necessary and that they may be undergoing. We are not always sure of how time here relates to time there, or even if they experience time as we currently do. Yet, still, it is our instinct to pray and assist them in those final finishing touches, as the Lord completes His masterpiece.