The hadith is in Sahih Muslim:
Once the Prophet, while passing through one of the graveyards of
Medina or Mecca heard the voices of two persons who were being
tortured in their graves. The Prophet (ﷺ) said, "These two persons are
being tortured not for a major sin (to avoid)." The Prophet (ﷺ) then
added, "Yes! (they are being tortured for a major sin). Indeed, one of
them never saved himself from being soiled with his urine while the
other used to go about with calumnies (to make enmity between
friends). The Prophet (ﷺ) then asked for a green leaf of a date-palm
tree, broke it into two pieces and put one on each grave. On being
asked why he had done so, he replied, "I hope that their torture might
be lessened, till these get dried." (sunnah.com)
From this hadith, some scholars say that putting flowers on graves is allowed.
I can't translate this fatwa, but if know Arabic, see this: IslamWeb.net. And some of those who said it's allowed, say that giving the price of those flowers as sadaqa on behalf of the dead is better.
Some others say it's not allowed because in another long hadith in sahih muslim the prophet (peace be upon him) mentioned that the reduction of punishment happened because of his shafaa (intercession):
he said (the prophet peace be upon him): I passed by two graves the occupants of which had been
undergoing torment. I liked to make intercession for them so that the
might be relieved of this torment y as long as these twigs remain
fresh
In Arabic:
قَالَ " إِنِّي مَرَرْتُ بِقَبْرَيْنِ يُعَذَّبَانِ فَأَحْبَبْتُ
بِشَفَاعَتِي أَنْ يُرَفَّهَ عَنْهُمَا مَا دَامَ الْغُصْنَانِ
رَطْبَيْنِ "
From this hadith, some scholars says that this act is private to the prophet (peace be upon him). So there is difference of opinions on this issue.