What he said passing the ruins
He covered his head and hurried the animal through.
لاَ تَدْخُلُوا عَلَى هَؤُلاَءِ الْمُعَذَّبِينَ إِلاَّ أَنْ تَكُونُوا بَاكِينَ، فَإِنْ لَمْ تَكُونُوا بَاكِينَ فَلاَ تَدْخُلُوا عَلَيْهِمْ، لاَ يُصِيبُكُمْ مَا أَصَابَهُمْ
Lā tadkhulū ʿalā hāʾulāʾi-l-muʿadhdhabīna illā an takūnū bākīn. Fa-in lam takūnū bākīna fa-lā tadkhulū ʿalayhim, lā yuṣībukum mā aṣābahum
Do not go in among these people who were punished unless you are weeping. And if you are not weeping, do not go in among them, so that what struck them does not strike you.
Where this comes from
They were passing the dwellings of Thamud. The instruction is not to avoid the place. It is about what you are feeling when you look at it, and treating other people's ruin as a spectacle is the thing named as dangerous.
The full narration
Narrated `Abdullah bin `Umar:Allah's Messenger (ﷺ) said, "Do not enter (the places) of these people where Allah's punishment had fallen unless you do so weeping. If you do not weep, do not enter (the places of these people) because Allah's curse and punishment which fell upon them may fall upon you
Source
Ṣaḥīḥ al-Bukhārī · 433
- Agreed upon as authentic (al-Bukhārī / Muslim)