This supplication should be recited when placing the deceased in the grave.
It is narrated from Ibn Umar (may Allah be pleased with them both) that the Messenger of Allah ﷺ said: “When you lower your dead into the grave, say: بسم الله وعلى ملة رسول الله.” In one narration the words are وعلي سنة رسول الله.
Reference: Sahih (authentic): Sahih Abi Dawud: 2752, Kitab al-Janaiz: Bab fi al-Du’a lil-Mayyit idha Wudi’a fi Qabrihi, Ahkam al-Janaiz: p. 192, Ahmad: 69/2, Abu Dawud: 3213, Tirmidhi: 1046, Ibn Majah: 1550