Narrated Ibn Abbas:
The Prophet once passed by two graves, and those two persons (in the graves) were being tortured. He said, “They are being tortured not for a great thing (to avoid). One of them never saved himself from being soiled with his urine, while the other was going about with calumnies (to make enmity between friends). He then took a green leaf of a date-palm tree split it into two pieces and fixed one on each grave. The people said, “O Allah’s Apostle! Why have you done so?” He replied, “I hope that their punishment may be lessened till they (the leaf) become dry.”
These two persons were getting punishment of the grave not because they committed some huge crimes, but just because one wasn’t very careful regarding his cleanliness and purity, and the other kept himself busy making enmity between friends.
Why are we so sure that our grave will be a spacious one? That the Earth will welcome us warmly? That the insects and worms won’t harm us? That the amount of time we spend lying in our graves (however long that may be) will be a ‘good’ time? What makes us so sure?
Coming to the part where Prophet (SAW) put leaves of the palm tree over the graves, hoping that their punishment will be reduced. Know, that we’re not supposed to do it. One, we don’t know who’s getting punished in their graves and who isn’t. Two, companions didn’t do it, so we won’t either.
Shaykh Ibn Baaz said:
That is not prescribed in Islam, rather it is bid’ah (an innovation), because the Messenger (peace and blessings of Allaah be upon him) only placed the palm-leaf stalk on the two graves of the people whose torment he was made aware of; he did not place them on any other graves. From that we know that it is not permissible to put them on graves, because the Prophet (peace and blessings of Allaah be upon him) said: “Whoever introduces anything into this matter of ours (Islam) that is not part of it, will have it rejected.” According to a version narrated by Muslim: “Whoever does anything that is not part of this matter of ours (Islam), will have it rejected.”
Similarly, it is not permissible to write on graves or to place flowers on them, because of the two hadeeth quoted above, and because the Prophet (peace and blessings of Allaah be upon him) forbade plastering over graves, erecting structures over them, sitting on them and writing on them.
Majallat al-Buhooth al-Islamiyyah, 68/50.
Read more here.