The reason and purpose behind the mourning rituals:
The Talmud questions whether the purpose of eulogizing the deceased is for the sake of the living [i.e. Yikra Dechayeh] or for the sake of the deceased [i.e. Yikra Deshachvi]. The Poskim, Rishonim and Achronim, likewise debate this issue regarding the mourning period and its subsequent laws. Practically, we find several reasons recorded behind the purpose of Aveilus, some being to benefit the deceased, while others to benefit the surviving relatives. The following are the reasons recorded:
A. For the relatives to repent:
The purpose behind the laws of mourning is for a person to receive a spiritual wake-up, and make an accounting of his soul. In general, most people do not become deeply motivated through mere thought and contemplation until an action occurs. The action of the [tragic and early] death of a relative with whom one shares a deep love according to nature, has a profound effect on the person. The purpose of the mourning is for the person to contemplate this death and arouse his pain and pity. This will then lead him to make an accounting of his own soul, of its purpose and its current focus. The Jewish religion professes the belief that the death of a relative, and the ensuing pain, is not something that comes on its own, but is due to man’s sins, and when a person recognizes this, he will be brought to Teshuvah. This negates the belief of the heretics who mistakenly think that death is just a matter of time, and just as animals die so too humans.
B. Alleviating the judgment of the soul of the deceased:
The Zohar states that after death, the body and soul are judged, and the soul cannot be elevated to the next world, Gan Eden, until its judgment is complete. This judgment is especially harsh within the first seven days of Shiva. It is for this reason that the relatives practice strict mourning laws throughout Shiva, as the pain that they experience helps alleviate the harshness of the judgment of the deceased. These laws then decrease throughout the Shloshim, as by then the judgment is less strict. The children continue to practice mourning customs after Shloshim, throughout the first 12 months, as Reshaim are judged in Gehinnom for 12 months, and the keeping of the mourning laws helps alleviate this judgment.
C. Kibud Av Vaeim:
By the children keeping the laws of Aveilus during the mourning period, they fulfill the Mitzvah of Kibud Av Vaeim, which applies even after their parent’s death.
 Sanhedrin 46b; See Michaber 344:10
 See Rama 344:10; Darkei Moshe 344; Maryu 4; Shut Ranach 50; Teshuvah Meahava 1:10, brought in Pischeiy Teshuvah 344:2; Iyun Yaakov Sanhedrin 47 and Shvus Yaakov 2:102, brought in Pischeiy Teshuvah 344:2; Rav Akiva Eiger 344:10 explains that whether Aveilus is on behalf of the dead or living is a dispute between the Rambam and Ramban, and we rule in 345 like the Rambam. He concludes with a Tzaruch Iyun Ledina; See Nitei Gavriel Vol. 2 1:7
 Sefer Hachinuch Mitzvah 264; See also Ramban in Hakdama to Toras Hadam; Rambam Avel 13:12; Nimukeiy Yosef Moed Katan 18a; Radbaz 3:555; Michaber 394:6; Beis Hilel Y.D. 381 “the main reason for Aveilus is for Teshuvah”
 Ramban ibid
 See Mavor Yabok Sefas Emes 20; Rav Poalim 1:51; Nitei Gavriel 1:1 footnote 1
 Zohar Vayakhel p. 129
 See Taz Y.D. 402:9; O.C. 568:4; Maharam Merothenberg Semachos 50; Mavor Yabok Sifsei Emes 20 and 21; Nitei Gavriel Vol. 2 62:1
 See Shach 344:9