One of the benefits of tefillah b'tzibbur is that it brings honor to Hashem. It is a public expression of our belief in Hashem. The Rambam (end of Bo) writes, "The purpose of all the mitzvos are that we should believe in Hashem and praise Him for creating us. For this purpose, the world was created. We don't know of any other reason for the creation, and the exalted Hashem has no interest in the world below except for when a person praises His G-d for creating him. This is why we raise our voices in prayer, and this is why we go to the beis kneses [to daven], and this is the specialty of tefillah b'tzibur. People should have a place where they gather to praise Hashem for creating them and bringing them into existence. They announce it in public, and they say, 'We are Your creations!'
This is the greatness of tefillah b'tzibur, and this is also the specialty of every mitzvah that one does in public. It is a kiddush Hashem; it sanctifies Hashem's name.
Someone told Reb Moshe Feinstein zt'l that he was called to perform a bris milah on Shabbos in a certain area, and all the people who live there are mechalel Shabbos. Reb Moshe (see Igros Moshe Yorah Deiah 156) told him that according to halachah, it is forbidden to be in a place with chillul Shabbos. The proof is from the Gemara Yoma that when the kohen gadol did the avodah on Yom Kippur, Bnei Yisrael came to watch him do it. This is because when a mitzvah is performed in public, it adds beauty to the mitzvah. So, it is also true the other way around. To be among people who are doing aveiros gives strength to the aveiros that are being performed there. (Therefore, Reb Moshe advised that he come and perform the bris milah, and to immediately leave afterwards.)
Just as there is a concept of הדרת עם ברוב מלך, to perform a mitzvah in public, and this brings honor to Hashem, there is also a concept of למלך בזיון, a disgrace for Hashem's honor.
Therefore, a person shouldn't go to a place where there are problems with the yiras Shamayim (such as where people speak lashon hara or where there is a problem with shemiras einayim). A person shouldn't say, "I won't sin. We have the lesson from Reb Moshe Feinstein that there is a prohibition to merely be in such a place."
