Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:9:17

It is not for the polytheists to maintain the mosques of Allah ˹while˺ witnessing against themselves with disbelief. ˹For˺ those, their deeds have become worthless, and in the Fire they will abide eternally.  

It is not for the idolaters to attend God’s places of worship (masājid, is also read in the singular, masjid), entering them or sitting in them, bearing witness, against themselves, to unbelief; those, their works have failed, ˹their works˺ are invalid, and in the Fire they shall abide.
القرآن:٩:١٧

مَا كَانَ لِلْمُشْرِكِينَ أَنْ يَعْمُرُوا مَسَاجِدَ اللَّهِ شَاهِدِينَ عَلَىٰ أَنْفُسِهِمْ بِالْكُفْرِ ۚ أُولَٰئِكَ حَبِطَتْ أَعْمَالُهُمْ وَفِي النَّارِ هُمْ خَالِدُونَ  

{ما كان للمشركين أن يعمُروا مَسْجِدَ الله} بالإفراد والجمع بدخوله والقعود فيه {شاهدين على أنفسهم بالكفر أولئك حبطت} بطلت {أعمالهم} لعدم شرطها {وفي النار هم خالدون}.