During the year of Tabuk, the Messenger of Allah ﷺ camped with the people at al-Hijr, near the dwellings of Thamud. The people drew water from the wells that Thamud used to drink from, and they kneaded dough with it and set up cooking pots filled with meat.The Messenger of Allah ﷺ ordered them to pour out the contents of the pots and to feed the dough to the camels. Then he moved on with them until he camped at the well from which the she-camel used to drink, and he forbade them from entering the dwellings of the people who had been punished.He said, "I fear that what afflicted them may afflict you, so do not enter their dwellings."
حدثنا عبد الصمد حدثنا صخر يعني ابن جويرية عن نافع
نزل رسول الله ﷺ بالناس عام تبوك نزل بهم الحجر عند بيوت ثمود فاستسقى الناس من الآبار التي كان يشرب منها ثمود فعجنوا منها ونصبوا القدور باللحم فأمرهم رسول الله ﷺ فأهراقوا القدور وعلفوا العجين الإبل ثم ارتحل بهم حتى نزل بهم على البئر التي كانت تشرب منها الناقة ونهاهم أن يدخلوا على القوم الذين عذبوا قال إني أخشى أن يصيبكم مثل ما أصابهم فلا تدخلوا عليهم
Its isnad is sahih. Bukhari (6:279) and Muslim (2:389) narrated it in abridged form, through the route of Ubaydullah from Nafi, but neither of them includes the phrase "and he forbade them," and so on. Bukhari also narrated it before this, likewise in abridged form, from the narration of Abdullah bin Dinar from Ibn Umar. The prohibition against entering upon these people except while weeping has already been mentioned several times, most recently at 4561.Suyuti quoted it in Durr Manthur (4:104) at length, in a manner similar to the version given here, but attributed it to Ibn Mardawayh alone, which falls quite short, for fear that someone unaware might think this story is not found in the six books, when in fact it is present in the Sahihayn in substance.Umdat Tafsir (5:73) (Araf).