Anas b. Malik reported that Allah's Messenger (ﷺ) came to a woman who had been weeping for her (dead) child, and said to her: Fear Allah and show endurance. She (not recognising him) said: You have not been afflicted as…
A hadith like this is narrated with the same chain of transmitters but with the addition of these words:" The Messenger of Allah (ﷺ) happened to pass by a woman (who was sitting) by the side of a grave."