Question: Why do we pray for the dead on the 3rd, 9th, and 40th day of a person's repose, and what is the basis for the practice?
St. John Chrysostom states that the practice of praying for the dead comes from the Apostles themselves: "Not in vain did the Apostles order that remembrance should be made of the dead in the dreadful Mysteries. They know that great gain resulteth to them, great benefit; for when the whole people stands with uplifted hands, a priestly assembly, and that awful Sacrifice lies displayed, how shall we not prevail with God by our entreaties for them?" (Homily 3 on Philippians).
The Church commemorates the dead at every liturgy, and in every liturgy (that of St. Basil the Great, St. John Chrysostom, St. James, etc.). But there are special days of commemorating the dead, and these commemorations also go back to the Apostles.
The Apostolic Constitutions state: "Let the third day of the departed be celebrated with psalms, and lessons, and prayers, on account of Him that arose in the space of three days; and let the ninth day be celebrated in remembrance of the living, and of the departed; and the fortieth day according to the ancient pattern: for so did the people lament Moses, and the anniversary day in memorial of him. And let alms be given to the poor out of his goods for a memorial of him" (Apostolic Constitutions 8:42).
St. Symeon of Thessaloniki says that the memorial on the 3rd day is in honor of the Trinity, the 9th day memorial is in honor of the nine ranks of angels, the 40th day memorial is in honor of Christ's Ascension on the 40th day, and the annual memorial signifies that the departed lives and ins immortal in the soul (Nikolaos P. Vassiliadis, The Mystery of Death, trans. Fr. Peter A. Chamberas (Athens, Greece: The Orthodox Brotherhood of Theologians, 1997), p. 422f).
An old article from Orthodox Life (The Church's Prayer for the Dead, Orthodox Life, 1978, no. 1, p.16f), summarizes the Church's teaching on this question:
"We commemorate the dead on the third day firstly, because those who have departed had been baptized in the Name of the Father, Son and Holy Spirit, the One God in three Persons, and had kept the Orthodox faith they received at holy baptism; secondly, because they preserved the three virtues which form the foundation of our salvation, namely: faith, hope and love; thirdly, because man's being possesses three internal powers—reason, emotion and desire—by which we all have transgressed. And since man's actions manifest themselves in three ways—by deed, word, and thought—by our commemoration on the third day we entreat the Holy Trinity to forgive the departed all transgressions committed by the three above-mentioned powers and actions. When St. Macarius of Alexandria besought the angel who accompanied him in the desert to explain to him the meaning of the Church's commemoration on the third day, the angel replied to him: "When an offering is made in church on the third day, the soul of the departed receives from its guardian angel relief from the sorrow it feels as a result of the separation from the body. This it receives because glorification and offering is made in the Church of God which gives rise in it to blessed hope, for in the course of the two days the soul is permitted to roam the earth, wherever it wills, in the company of the angels that are with it. Therefore, the soul, loving the body, sometimes wanders about the house in which his body had been laid out, and thus spends two days like a bird seeking its nest. But the virtuous soul goes about those places in which it was wont to do good deeds. On the third day, He Who Himself rose from the dead on the third day commands the Christian soul, in imitation of His resurrection, to ascend to the Heavens to worship the God of all."
On the ninth day, the Holy Church offers prayers and the Bloodless Sacrifice for the departed, that his soul be accounted worthy to be numbered among the choirs of the saints through the prayers and intercession of the nine ranks of angels. St. Macarius of Alexandria, in accordance with the angel's revelation, says that after worshipping God on the third day, it is commanded to show the soul the various pleasant habitations of the saints and the beauty of Paradise. The soul considers all of this for six days, lost in wonder and glorifying the Creator of all. Contemplating all of this, it is transformed and forgets the sorrow it felt in the body. But if it is guilty of sins, at the sight of the delights of the saints it begins to grieve and reproach itself, saying: "Woe is me! How much I busied myself in vanity in that world! Enamored of the gratification of lust, I spent the greater portion of my life in carelessness and did not serve God as I should, that I too might be accounted worthy of this grace and glory. Woe is me! Poor me!" After considering all the joys of the righteous in the course of six days, it again is borne aloft by the angels to worship God.
From earliest antiquity the Holy Church has correctly and devoutly made it a rule to commemorate the departed in the course of forty days, and on the fortieth day in particular. As Christ was victorious over the devil, having spent forty days in fasting and prayer, so the Holy Church likewise, offering for the departed prayers, acts of charity and the Bloodless Sacrifice throughout the forty days, asks the Lord's grace for him to conquer the enemy, the dark prince of the air, and that he receive the Heavenly Kingdom as his inheritance. St. Macarius of Alexandria, discussing the state of man's soul after the death of the body, says: "After the second adoration, the Master of all commands that the soul be led to hell and that it be shown the places of torment there, the various parts of hell, and the diverse tortures of the wicked, in which the souls of sinners ceaselessly wail and gnash their teeth. The soul is borne about these various places of torment for thirty days, trembling lest it itself be imprisoned therein. On the fortieth day it is once again borne aloft to adore the Lord God, and it is at this time that the Judge determines the place of confinement proper to it in accordance with its deeds. This is a great day for the deceased, for it determines his portion until the Dread judgment of God, and therefore, the Holy Church correctly commands that fervent prayer be made for the dead on this day."
In additions to these days, there are days appointed throughout the Church year on which the dead are specially commemorated. That Christians have always prayed for the dead is one of the most well attested Traditions of the Church, and is found in the earliest writings of the Church, throughout the fathers, and is a practice that is also found in Judaism and Islam. Only with the advent of Protestantism do you find Christians that do not pray for the dead, but not even all Protestants reject prayers for the dead.