It was narrated that Ibn ‘Umar (may Allaah be pleased with him) said: When the Messenger of Allaah (peace and blessings of Allaah be upon him) passed by al-Hijr (the land of the people of Thamood) he said: “Do not enter the dwellings of those who wronged themselves, lest what befell them befall you, unless you are weeping.” Then the Messenger of Allaah (peace and blessings of Allaah be upon him) covered his head and walked quickly until he had left the valley. Narrated by al-Bukhaari, 3380; Muslim, 2980.
Al-Nawawi included this hadeeth in a chapter entitled “Weeping and feeling fear when passing by the graves of the wrongdoers and the places where they were killed, and expressing one's need of Allaah, and being careful not to be negligent in that.” Riyaadh al-Saaliheen, p. 373.