And this was his vision: That Onias, who had been high priest, a virtuous and a good man, reverend in conversation, gentle in condition, well spoken also, and exercised from a child in all points of virtue, holding up his hands prayed for the whole body of the Jews. This done, in like manner there appeared a man with gray hairs, and exceeding glorious, who was of a wonderful and excellent majesty. Then Onias answered, saying, This is a lover of the brethren, who prayeth much for the people, and for the holy city, to wit, Jeremias the prophet of God. Whereupon Jeremias holding forth his right hand gave to Judas a sword of gold, and in giving it spake thus, Take this holy sword, a gift from God, with the which thou shalt wound the adversaries (2 Mac 15:12-15).
In this passage, we see the vision of Judas Maccabee of an angel appearing to Onias, “who had been high priest” while Onias was praying for the Jews. The departed Onias states this angel “is a lover of the brethren, who prayeth much for the people.” Thus we are led to understand that the departed are aware of us and pray for us, just as the angels pray for us. Therefore, those who have “fallen asleep”, those who are “kept by the power of God”, those whose God is “the God of the living, and not the dead”, and those who are “like the angels”, can hear our prayers and intercede for us, just as our brothers and sisters among the living can intercede for us.
It is not just prayer to the dead (asking them to intercede for us, or for others), but also prayer on behalf of the dead that is at issue here. In 2 Maccabees we see the aftermath of a great victory. Having routed the troops of Gorgias, the governor of Idumea (from which was to come King Herod), Judas had his men gather up the bodies of the fallen for burial. When they found that some of the fallen were wearing Jamnian idols, Judas took a collection and offered it as a sin offering on their behalf.
And when he had made a gathering throughout the company to the sum of two thousand drachms of silver, he sent it to Jerusalem to offer a sin offering, doing therein very well and honestly, in that he was mindful of the resurrection: for if he had not hoped that they that were slain should have risen again, it had been superfluous and vain to pray for the dead. And also in that he perceived that there was great favor laid up for those that died godly, it was an holy and good thought. Whereupon he made a reconciliation for the dead, that they might be delivered from sin. (2 Maccabees 12:43-45)
The passage connects the belief in the resurrection with prayer for the dead, so as to “set them free from their transgression.” The apostle Paul alludes to this passage when he discusses the baptism of the dead.
Otherwise, what do people mean by being baptized on behalf of the dead? If the dead are not raised at all, why are people baptized on their behalf? (1 Corinthians 15:29)
To demonstrate the connection between resurrection, prayer for the dead, and baptism, we must allow St. John Chrysostom to have his say. In Homily XL  on 1 Corinthians, Chrysostom begins by providing the explanation of baptism given to the recently baptized Christians. In baptism we are buried with Christ in His death, and resurrected with Christ unto new life. This resurrection is not symbolic; the words are performative words, in that they do what they say.
“I believe in the resurrection of the dead,” and upon this faith we are baptized. For after we have confessed this together with the rest, then at last are we let down into the fountain of those sacred streams. This therefore Paul recalling to their minds said, “if there be no resurrection, why art thou then baptized for the dead?” i.e., the dead bodies. For in fact with a view to this art thou baptized, the resurrection of thy dead body, believing that it no longer remains dead. And thou indeed in the words makest mention of a resurrection of the dead; but the priest, as in a kind of image, signifies to thee by very deed the things which thou hast believed and confessed in words. When without a sign thou believest, then he gives thee the sign also; when thou hast done thine own part, then also doth God fully assure thee. How and in what manner? By the water. For the being baptized and immersed and then emerging, is a symbol of the descent into Hades and return thence. Wherefore also Paul calls baptism a burial, saying, “Therefore we are buried with Him by baptism into death.” (Rom. vi. 4.)
What Paul is saying is that if the dead are not raised, then why are we baptized? If baptism does not affect the resurrection of the body, then what is the point? On this subject, we shall let Chrysostom speak.
Yet again, because the term Resurrection is not sufficient to indicate the whole: for many after rising have again departed, as those in the Old Testament, as Lazarus, as they at the time of the crucifixion: one is bid to say, “and the life everlasting,” that none may any longer have a notion of death after that resurrection. These words therefore Paul recalling to their minds, saith, “What shall they do which are baptized for the dead?” “For if there be no resurrection,” saith he, “these words are but scenery. If there be no resurrection, how persuade we them to believe things which we do not bestow? …This then he here saith of those who are baptized also. “What shall they do which are baptized,” saith he, “having subscribed to the resurrection of dead bodies, and not receiving it, but suffering fraud? And what need was there at all of this confession, if the fact did not follow?
Is prayer for the dead efficacious? Does it do anything? Does it affect any change in the eternal status of those who have departed this life? Of this the scriptures tell us nothing. We cannot draw back the curtain; we cannot peer beneath the veil. And yet we cannot deny that the believing Jews of the Old Testament period had this belief and practice. To what end, we do not know, except that we trust in the mercy and lovingkindness of God.
 (P. Schaff, NPNF1-12. Saint Chrysostom: Homilies on the Epistles of Paul to the Corinthians 2002, 379-380)
 (P. Schaff, NPNF1-12. Saint Chrysostom: Homilies on the Epistles of Paul to the Corinthians 2002, 380-381)