All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
The Prophetic narration which you mentioned in the question is reported by Imaam Muslim, Abu Daawood, An-Nasaa’i and others, may Allaah have mercy upon all of them. Its meaning is clear, that if a person were to sit on a live coal which will burn him, then this is better, and less harmful for him than sitting on a grave. This narration is evidence that it is not permissible to sit on graves. The majority of scholars are of the view that it is forbidden to sit on graves.
However, we have not come across any text which specifies the time and the occasion when the Prophet said this narration.
Nonetheless, respecting graves is achieved by avoiding what is religiously prohibited to do towards them [graves], like sitting on them, or performing an act of worship at the grave in order to get closer to Allaah, and other innovations. It is also achieved by doing what is permissible to do, like supplicating Allaah to forgive the dead and have mercy upon them, and visiting the grave for the purpose of admonition and remembering death.
Allaah Knows best.