This was not something the Prophet used to do. However, you may do that since the Companion Ibn `Umar liked to do it, but you should not assume that it was something taught by the Prophet.
What the Qur’an and Sunnah Say
The Messenger of Allah said: “Recite Surah Yasin on your dead people.” (Abu Dawud #3112) This report was graded weak by Ibn Arabi, Adh-Dhahabi, and An-Nawawi.
What the Scholars Said
Abdullah ibn Umar said, “When one of you passes away, do not keep his body for long and take him quickly to his grave, and have the opening verses of Surat al-Baqarah recited at his head and the concluding verses of Surat al-Baqarah recited at his feet.” (Al-Bayhaqi in Shu’ab al-Iman, this was mistakenly attributed to the Prophet)
Imam Ibn Abidin said, “Ibn Umar liked to recite by the grave the opening (verses 1-5) and concluding verses (285-286) of Surat al-Baqarah upon the completion of the burial.” (Radd al-Muhtar 2:237)
“It is slightly recommended after the burial procedure is over to wait by the grave for a duration in which a camel can be slaughtered and its meat distributed, reciting Qur’an and supplicating for the deceased…recitation of the Qur’an [by the grave] is not disliked according to Imam Muhammad and our [Hanafi] jurists have taken his position [on this issue].” (Al-Fatawa al-Hindiyya, 1:166)
Shaykh Mustafa Umar