There are beliefs that the dead can hear us and, by those beliefs, we don't know what they are going through, their souls might be in suffering, my be stuck to a reality that is no longer theirs. Believers pray for the dead to let them go. It's a way to tell them they are dead but people still remember so they can rest in peace.
Other way of praying for the dead is, if we think about it, when people pray to Jesus or Mary, or any other saint which were, once, people who were living. Even though believers think those souls are in peace, they had no sins, they pray to them for help. Sometimes people also do that with loved ones... for help and comfort of the living and not to change the final destiny or comfort the dead.