We pray for the repose of the souls of our loved ones (in my case, my mom and my grandparents) so that whatever purification they are enduring in purgatory may be lessened so that they will enter into the peace of God’s kingdom. In other words, we are praying for the souls in purgatory. We are offering expiation for them.
It does have its grounding in the Old Testament. Recall what Judas Maccabees did. He found amulets in the bodies of his soldiers. Immediately, he collected money from his compatriots and had a sacrificial offering made as expiation for the men, trusting in God’s mercy. In fact, the reading from this passage of 1st Maccabees is often read in Masses for the Dead and funeral Masses. There is also reference to purification of the souls of the just in the book of Wisdom/Sirach.