We passed by al-Hijr with the Messenger of Allah ﷺ, and the Messenger of Allah ﷺ said to us, "Do not enter the dwellings of those who wronged themselves unless you are weeping, out of fear that what befell them may befall you." Then he urged his mount on and quickened his pace until he had left the place behind.
مررنا مع رسول الله ﷺ على الحجر، فقال لنا رسول الله ﷺ: لا تدخلوا مساكن الذين ظلموا أنفسهم، إلا أن تكونوا باكين، حذرا أن يصيبكم مثل ما أصابهم. ثم زجر فأسرع حتى خلفها.
Bukhari narrated it in the Hadiths of the Prophets (3381), and Muslim in Asceticism and Softening of Hearts (39:2980), both through Yunus, from Ibn Shihab Zuhri, from Salim bin Abdullah, that Abdullah bin Umar said, and he mentioned it. The wording is Muslim's, and Bukhari's wording is similar.