‘Abdullah bin ‘Umar narrated that the Messenger of Allah (صلى الله عليه و سلم) and his Companions passed by al-Hijr, which was the location of the dwellings of the people of Thamud. So, the Prophet turned to them and said: “Do not approach the dwellings of these people who have been punished except that you are weeping. If you will not weep while doing so, do not approach them lest you be struck with the same punishment they were struck with.”
This was reported by al-Bukhari (433) and Muslim (2970).
In ‘Fath al-Bari’ (1/632), Ibn Hajar commented with the following: