The Mechaber (154:11) rules that candles that were used for idol worship and were given or sold to a Jew after they were extinguished, may not be lit in a Bais Haknesses. It may be used for one’s own personal use since it is no longer set aside for Avodah Zarah (Rema). However it is inappropriate to be used for a Bais Haknesses.
There is a difference of opinion if a place of worship of the goyim may be turned into a Bais Haknesses. The Mishna Berurah brings the Magen Avrohom who holds it is permissible. The reason is because the structure itself was never worshipped. The Elya Rabah is stringent and rules that it should not be used for a Bais Haknesses. The Mishnah Berura rules that the minhag is to be lenient. Reb Moshe Feinstein zt”l rules more stringently and it should not be done. The Chasam Sofer also rules this way. However if they were already turned into a Bais Haknesses there is no prohibition to daven there.
The Biur Halacha stresses that the Magen Avrohom permits it only when they did not have idols in the place of worship. However if there were idols, it would be prohibited to turn it into a Bais Haknesses. Then it is considered that the structure served the Avodah Zarah similar to the candles, and it is inappropriate to be used as a Bais Haknesses. Many poskim hold that the cross is a form of Avodah Zarah, and therefore all of the places of worship that have a cross may not be turned into a Bais Haknesses even after everything is removed.
Reb Moshe zt”l says that even according to the Magen Avrohom, it is only permissible if the building was bought. To rent it from them is prohibited. If it was only used for a school or a place where their priests stayed then everyone agrees it can even be rented from them. One has to be certain that there were never any idols there.
If a building was originally built as a Bais Haknesses and was forcibly taken away by the goyim for a house of worship, if and when they are able to take it back it may still be used as a Bais Haknesses. The original kedusha never left. Everything should be taken out and the walls should be repainted.
There is no prohibition to make a shul in a place that was used for immoral and improper behavior as long as the building is bought. However if it is only going to be rented and after some time it will once again be used for such behavior, it is prohibited to rent it.1
Prepared by R’ Avrohom Yehoshua Ziskind
1Sources: Mishnah Berurah, Biur Halacha, Piskei Teshuvos