Explanation
This ḥadīth, which al-Nawawī (may Allah have mercy on him) cites in Riyāḍ al-Ṣāliḥīn under the chapter “The Virtue of Ablution,” is narrated from Abū Hurayrah: the Prophet (peace and blessings be upon him) came to the cemetery and said, “Peace be upon you, abode of a believing people, and, if Allah wills, we shall soon be joining you.”
At first the Prophet (peace be upon him) had forbidden visiting graves, for the people had only recently left polytheism and he feared that their hearts might grow attached to the graves and fall into temptation because of them. Therefore he prohibited such visits.
When faith had become firmly established in their hearts, however, he instructed them to visit the graves and said, “I had previously forbidden you from visiting graves; now visit them, for they remind one of death”—and in another wording—“they remind one of the Hereafter.”
Thus he commanded the visitation and clarified its great wisdom: it reminds the living person who is still walking upon the earth that today he is on its surface and tomorrow he will be beneath it, though he does not know when that moment will arrive. A person may awaken on the earth’s surface in the morning and be buried beneath it by nightfall, or retire above ground at night and be under it by daybreak.
Accordingly, visiting cemeteries serves as a reminder of death and the Hereafter. When someone passes by a graveyard and reflects, he pictures his father, his uncle, his wife, his brother, and the like—people who only yesterday were with him eating, drinking, and enjoying themselves, yet now they are detained by their deeds in the graves. He recalls that at this very time last year they were among us, delighted with worldly life and content with it; but now they have departed and are mortgaged to their deeds: whoever does good will find it, and whoever does evil will find it—so the visit stirs a reminder