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.'"
أنه مات ابن له بقديد، أو بعسفان، فقال: يا كريب! انظر ما اجتمع له من الناس، قال: فخرجت فإذا ناس قد اجتمعوا له، فأخبرته، فقال: تقول هم أربعون؟ قال: نعم، قال: أخرجوه، فإني سمعت رسول الله ﷺ يقول: ما من رجل مسلم يموت فيقوم على جنازته أربعون رجلا، لا يشركون بالله شيئا إلا شفعهم الله فيه.
Muslim narrated it in the Book of Funerals (948) through several routes from Ibn Wahb, who said, Abu Sakhr informed me, from Sharik bin Abdullah bin Abu Nimr, from Kurayb, the freed slave of Ibn Abbas, from Ibn Abbas, and he related the hadith.