Abu Hurairah reported,

The Messenger of Allah ﷺ said, "Whoever follows the funeral procession of a Muslim out of faith and seeking reward, and remains with it until the prayer is performed and the burial is completed, will return with two qirats of reward, each qirat like the mountain of Uhud. And whoever prays over it and then returns before the burial will return with one qirat."

Azami 3670

Sahih

عن أبي هريرة قال

إن رسول الله ﷺ قال: من اتبع جنازة مسلم إيمانا واحتسابا، وكان معه حتى يصلى عليها، ويفرغ من دفنها فإنه يرجع من الأجر بقيراطين كل قيراط مثل أحد، ومن صلى عليها ثم رجع قبل أن تدفن فإنه يرجع بقيراط.

الأعظمي 3670صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Funerals
Chapter
Deceased, carrying the funeral bier, and standing for it
Section
Following funeral processions and its virtue
Numbering
Jami al-Kamil 3670 (2nd edition)