Abdullah bin Abbas reported,

A son of his died at Qudayd, or at Usfan, and he said, "Kurayb, go and see how many people have gathered for him."Kurayb said, "I went out, and there were people who had gathered for him, so I informed him."He asked, "Would you say they are forty?"I replied, "Yes."He said, "Bring him out, for I heard the Messenger of Allah ﷺ say, 'There is no Muslim man who dies and forty men, who associate nothing with Allah, stand in prayer over his funeral, except that Allah accepts their intercession for him.'"

Azami 3727

Sahih

عن ابن عباس

أنه مات ابن له بقديد، أو بعسفان، فقال: يا كريب! انظر ما اجتمع له من الناس، قال: فخرجت فإذا ناس قد اجتمعوا له، فأخبرته، فقال: تقول هم أربعون؟ قال: نعم، قال: أخرجوه، فإني سمعت رسول الله ﷺ يقول: ما من رجل مسلم يموت فيقوم على جنازته أربعون رجلا، لا يشركون بالله شيئا إلا شفعهم الله فيه.

الأعظمي 3727صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Funerals
Chapter
Prayer over the deceased
Section
Those for whom forty pray will have their intercession accepted
Numbering
Jami al-Kamil 3727 (2nd edition)
Azami 3727