Mishkat al-Masabih 1651
وَعَنْ أَبِي هُرَيْرَةَ رَضِيَ اللَّهُ عَنْهُ قَالَ: قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: «مَنِ اتَّبَعَ جَنَازَةَ مُسْلِمٍ إِيمَانًا وَاحْتِسَابًا وَكَانَ مَعَهُ حَتَّى يُصَلَّى عَلَيْهَا وَيُفْرَغَ مِنْ دَفْنِهَا فَإِنَّهُ يَرْجِعُ مِنَ الْأَجْرِ بِقِيرَاطَيْنِ كُلُّ قِيرَاطٍ مِثْلُ أُحُدٍ وَمَنْ صَلَّى عَلَيْهَا ثُمَّ رَجَعَ قَبْلَ أَنْ تُدْفَنَ فَإِنَّهُ يَرْجِعُ بقيراط»
From Abu Hurayrah, may Allah be pleased with him, who said: The Messenger of Allah ﷺ said: "Whoever follows the funeral of a Muslim out of faith and hoping for reward, and remains with it until the prayer is offered over it and its burial is finished, returns with a reward of two qirats, each qirat like Uhud. And whoever prays over it and then returns before it is buried returns with one qirat."