thus Allah, exalted be He, forbade the believers from even entering without permission and declared it unlawful. If mere entry is prohibited, the usurpation of a house or a plot of land and residing in it is even more emphatically forbidden, and performing the prayer there is more forbidden still. For that reason the prayer on usurped land is unanimously held to be unlawful, as al-Nawawī reports. The jurists only disagreed about whether such a prayer is valid: the majority maintain that it is, whereas Aḥmad and Ibn Ḥazm, in al-Muḥallā and al-Aḥkām fī Uṣūl al-Aḥkām, held that it is invalid. The view of the majority is closer to the truth, for the prohibition is not specific to the prayer itself and therefore does not negate its validity. Allah knows best.
Seventh: the Mosque of Harm (Masjid al-Dirār) that stood near Qubāʾ, and by extension every mosque erected with the intention of causing harm and division among the Muslims. Concerning it Allah says: “And there are those who took for themselves a mosque to cause harm, disbelief, and disunity among the believers, and as an outpost for those who had previously fought against Allah and His Messenger… Do not ever stand in it to pray; a mosque founded upon piety from the very first day is worthier for you to stand in” (Q 9:107-108).
The Qur’anic commentators summarize the episode as follows: The clan of ʿAmr b. ʿAwf built the Mosque of Qubāʾ and asked the Prophet ﷺ to visit them, whereupon he prayed in it. Their kinsmen, the Banū Ghanm b. ʿAwf, envied them and said, “Let us build a mosque and invite the Prophet ﷺ to come and pray for us as he prayed…"