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."
إن رسول الله ﷺ قال: من اتبع جنازة مسلم إيمانا واحتسابا، وكان معه حتى يصلى عليها، ويفرغ من دفنها فإنه يرجع من الأجر بقيراطين كل قيراط مثل أحد، ومن صلى عليها ثم رجع قبل أن تدفن فإنه يرجع بقيراط.
Bukhari narrated it in the Book of Faith (47), from Ahmad bin Abdullah bin Ali Manjufi, who said, Rawh narrated to us, who said, Awf narrated to us, from Hasan and Muhammad, from Abu Hurairah, and he related it.Uthman the muezzin corroborated him, saying, Awf narrated to us, from Muhammad, from Abu Hurairah, from the Prophet ﷺ, similarly. End.Hasan here is Ibn Abu Hasan Basri, and there is disagreement over whether he actually heard from Abu Hurairah. The correct view is that he did not hear from him, and he frequently narrates with gaps in his chain (mursal). This is why Bukhari relied on the narration of Muhammad, who is Ibn Sirin, with Hasan's narration serving merely as a corroboration for it.Awf is Ibn Abu Jamilah, whose kunya is Abu Sahl. Uthman the muezzin is Ibn Haytham, one of Bukhari's teachers.