Praise be to Allah.
It is not permissible to sit in a place in which sin is committed openly, unless one is forced to do so, because denouncing evil with one’s hand (by taking action), one's tongue (by speaking against it) or one's heart (by hating it) is something that is obligatory, and sitting in a place where evils are being committed and not denouncing them is contrary to that. Allaah says (interpretation of the meaning):
“And it has already been revealed to you in the Book (this Qur’aan) that when you hear the Verses of Allaah being denied and mocked at, then sit not with them, until they engage in a talk other than that; (but if you stayed with them) certainly in that case you would be like them”
al-Qurtubi (may Allaah have mercy on him) said: The words of Allaah, “then sit not with them, until they engage in a talk other than that” mean, something other than kufr (disbelief). “(But if you stayed with them) certainly in that case you would be like them” – this indicates that it is obligatory to avoid people of sin if they are openly committing evil, because the one who does not avoid them is approving of their deeds, and approving of kufr is also kufr. Allaah says “(but if you stayed with them) certainly in that case you would be like them”, so everyone who sits in a gathering where sin is committed and does not denounce them will share the burden of sin with them.
They should be denounced if they speak of sin or commit sin; if one cannot denounce them then he should leave them so that he will not be one of those mentioned in this verse.
It was narrated that ‘Umar ibn ‘Abd al-‘Azeez caught some people who were drinking alcohol, and it was said to him that one of the people present was fasting. He had the punishment carried out on him too, and he recited this verse: “(but if you stayed with them) certainly in that case you would be like them”, i.e., approval of sin is also a sin. End quote.
Al-Jassaas said in Ahkaam al-Qur’aan (2/407): This verse indicates that it is obligatory to denounce evil to the one who does it, and part of denouncing it is showing one’s dislike of it if it is not possible to remove it, and not sitting with the one who does it, and leaving him until he stops it and does something else. End quote.
Shaykh Ibn Baaz (may Allaah have mercy on him) said: Denouncing in one's heart is obligatory for everyone, which means hating the evil and leaving the people if one is unable to change it with one's words or actions, because Allaah says (interpretation of the meaning):
“And when you (Muhammad صلى الله عليه وسلم) see those who engage in a false conversation about Our Verses (of the Qur’aan) by mocking at them, stay away from them till they turn to another topic. And if Shaytaan (Satan) causes you to forget, then after the remembrance sit not you in the company of those people who are the Zaalimoon (polytheists and wrongdoers)”
End quote from al-Durar al-Saniyyah fi’l-Ajwabah al-Najdiyyah (16/142).
Moreover there is the fear that the faith of the one who sits in such places will be weakened, and protective jealousy (for Islam) will disappear from his heart, and the Shaytaan may call him to take part in some of the sin. Allaah says (interpretation of the meaning):
“O you who believe! Follow not the footsteps of Shaytaan (Satan). And whosoever follows the footsteps of Shaytaan (Satan), then, verily, he commands Al‑Fahsha’ [i.e. to commit indecency (illegal sexual intercourse)], and Al‑Munkar [disbelief and polytheism (i.e. to do evil and wicked deeds; and to speak or to do what is forbidden in Islam)]”
But… if a Muslim needs to sit in such places, such as if he is travelling and cannot find any other place to rest, then he may sit there, so long as he keeps away from the people who are committing sin as much as he can, and he sits there only as long as he needs to, then leaves.
And Allaah knows best.