From the Prophet ﷺ. And Abdullah bin Saeed narrated to us, Abu Khalid al-Ahmar narrated to us, Hajjaj narrated to us, from Nafi, from Ibn Umar, who said, "When the Prophet ﷺ placed the deceased into the grave, he would say, 'In the name of Allah and upon the religion of the Messenger of Allah.'"Abu Khalid once said, "When the deceased was laid in the side-niche of the grave, he would say, 'In the name of Allah and upon the way of the Messenger of Allah.'"Hisham said in his version, "In the name of Allah, in the path of Allah, and upon the religion of the Messenger of Allah."
حدثنا هشام بن عمار حدثنا إسمعيل بن عياش حدثنا ليث بن أبي سليم عن نافع
عن النبي ﷺ ح و حدثنا عبد الله بن سعيد حدثنا أبو خالد الأحمر حدثنا الحجاج عن نافع عن ابن عمر قال كان النبي ﷺ إذا أدخل الميت القبر قال بسم الله وعلى ملة رسول الله وقال أبو خالد مرة إذا وضع الميت في لحده قال بسم الله وعلى سنة رسول الله وقال هشام في حديثه بسم الله وفي سبيل الله وعلى ملة رسول الله
Sourcing, sahih. Tirmidhi reported it in the Book of Funerals, chapter on what is said when the deceased is placed in the grave. Its chain contains Hajjaj bin Artah, no. 1046, from Abdullah bin Saeed Ashaj, with similar wording, in the second chain, and Tirmidhi said, hasan gharib. Artah has already been discussed, nos. 496 and 1129. The first route contains Layth bin Abu Salim, no. 208, so that chain is daif. It has corroborating narrations in Abu Dawud, no. 3213, and elsewhere.Hakim reported, 1/366, with a sahih chain, from Bayadi , from the Messenger of Allah ﷺ, who said, "When the deceased is placed in his grave, those placing him in the niche should say, 'In the name of Allah, by Allah, and according to the religion of the Messenger of Allah ﷺ.'"Hakim and others reported, with a sahih chain, from Ibn Umar, that whenever he placed the deceased in his grave (in another narration, whenever he placed a deceased person in his grave, per Bayhaqi), he would say, "In the name of Allah, and according to the sunnah of the Messenger of Allah" (in another narration, "and according to the religion of the Messenger of Allah ﷺ", per Bayhaqi).Bayhaqi reported, 4/56, with a strong chain, from Ali
, that he placed a deceased person in his grave and said, "O Allah, your servant and son of your servant has come to you, and you are the best one to be come to. We know nothing of him but good, and you know him best. He used to bear witness that there is no god but Allah and that Muhammad is the Messenger of Allah, so forgive him his sin and make spacious for him his entrance."