The Messenger of Allah ﷺ said, "Whoever follows a funeral procession until it is completed receives two qirats of reward. If he returns before it is completed, he receives one qirat."
أخبرنا محمد بن عبد الأعلى قال حدثنا خالد قال حدثنا أشعث عن الحسن
قال رسول الله ﷺ من تبع جنازة حتى يفرغ منها فله قيراطان فإن رجع قبل أن يفرغ منها فله قيراط
[Sahih] Ahmad reported it, 5/57, from the hadith of Ashath bin Abdul-Malik Humrani with this chain, and it is in Kubra, hadith 2068. The preceding hadith serves as a corroborating witness for it, and the meaning of "until he is finished with it" is "until he is buried." See Musnad, 4/86 and elsewhere. Khalid is Ibn Harith, and Hasan Basri has already been mentioned, hadith 36.