Volume 3, Book 34, Number 329 :
Narrated by ‘Aisha (radiallaahu `anhaa)
Allah’s Apostle (sallallaahu `alayhi wasallam) said, “An army will invade the Ka’ba and when the invaders reach Al-Baida’, all the ground will sink and swallow the whole army.” I said, “O Allah’s Apostle (sallallaahu `alayhi wasallam)! How will they sink into the ground while amongst them will be their markets (the people who worked in business and not invaders) and the people not belonging to them?” The Prophet (sallallaahu `alayhi wasallam) replied, “all of those people will sink but they will be resurrected and judged according to their intentions.”
This is one of the prophecies made by the Prophet (sallallaahu `alayhi wasallam) of which Allah gave him knowledge of. Proof of his prophet-hood.
It’s yet to happen, and only Allah knows whose army it’ll be.
What’s relevant to us is the lesson in it: everyone will be judged by their intentions, not the apparent actions. Someone could go to the market remembering Allah and running their errands while another could be involved in a sin being in the same place. Let’s say both of them were in that market at the same time and the calamity took place, would they be resurrected to see the same fate? No. They’ll be judged based on their intentions.
Another thing: being in the company of bad people can be dangerous. You might not be doing what they’re doing but you just might see the same fate as theirs. If a calamity befalls them being there, it befalls you as well. Avoid bad places + bad people.