Sefer Chasidim: Escorting the Dead 4
When a student dies, one who analyzed and probed the halachic rulings of his rabbi, the rabbi will come to meet him in the World to Come. And so we read in the Talmud, “Ravina Said, “When I pass away, Rav Chia and Rav Oshaia will come to meet me, since I am explaining the mishnaic text in accordance with their teaching.’ (Bava Metzia 62b)” (Sefer Chasidim # 456 – Translated by Avraham Yaakov Finkel)
When Abraham escorted Sarah to the grave, he knew that God would come to greet her because she always taught people about God and His Will.
When we escort the dead we are also going to meet those who will come from heaven to greet the deceased.
You can find similar ideas in Shach, Choshen Mishpat end of #91. Mekor Chaim in the name of Maginei Shlomo and Maggid Meisharim.