Question: If the imām of the central mosque is not acceptable, is praying at home better, or in the mosque? And does this apply equally to the Two Sanctuaries and to other mosques?
Answer (and Allah grants success): If it is possible in that situation to pray in the mosque without suffering harm, then praying in the mosque is better—based on His saying, Exalted is He: “In houses which Allah has permitted to be raised and in which His Name is mentioned—glorifying Him therein in the mornings and the evenings are men whom neither commerce nor sale distracts from the remembrance of Allah …” [An-Nūr:36–37]. This applies equally to the Two Sanctuaries and to other mosques.
Source : Min Thimār al-ʿIlm wa al-Ḥikmah vol.1