Praise be to Allaah.
Yes, it is permissible to buy them and make them into mosques, because by doing so you are using them for a better purpose than they were used for previously. The evil is not part of the nature of the place itself, it is just something that happened there because of the purpose for which the place was used. Once it is put to a good use, the evil disappears and it becomes a good place.
Sheikh Muhammed Salih Al-Munajjid