Reference: Fataawa li Ahlil-Mayyit – Question 30, Page 32
al-Muntaqaa min Fataawa al-Fowzaan – Volume 1, Page 195
Question: Is it permissible to write the name of the deceased or an aayah from the Qur.aan on a headstone by the grave?
Response: It is not permissible to write the name of the deceased on a headstone or on anything else by the grave, since the Messenger ﷺ forbade that, even if it be an aayah from the Qur.aan, or a single word, or even a single letter – this is [all] impermissible.
However, if the grave is indicated with a sign other than writing, so as to identify it for [future] visits and extending the greeting [upon visiting], such as defining a line [or groove in the earth], or placing a stone by the grave without any writing on it, then there is no harm in this.
As for writing, then this is not permissible, because the writing is a means to shirk. So [sometime later] a generation may come where the people will say: “Indeed the details of this person have only been written on the gravestone because this person was good and benefited the people.” And as such, worshiping the grave has occurred.