Al-Hasan Al-Basri said that,
﴿وَعَهِدْنَآ إِلَى إِبْرَهِيمَ وَإِسْمَـعِيلَ﴾
(And We gave Our 'Ahd (command) to Ibrahim and Isma`il) means, "Allah ordered them to purify it from all filth and impurities, of which none should ever touch it.'' Also, Ibn Jurayj said, "I said to `Ata', `What is Allah's `Ahd' He said, `His command.''' Also, Sa`id bin Jubayr said that Ibn `Abbas commented on the Ayah,
﴿أَن طَهِّرَا بَيْتِىَ لِلطَّآئِفِينَ وَالْعَـكِفِينَ﴾
(that they should purify My House (the Ka`bah) for those who are circumambulating it, or staying (I`tikaf)) "Purify it from the idols.'' Further, Mujahid and Sa`id bin Jubayr said that,
﴿طَهِّرَا بَيْتِىَ لِلطَّآئِفِينَ﴾
(purify My House for those who are circumambulating it) means, "From the idols, sexual activity, false witness and sins of all kinds.''
(for those who are performing Tawaf (circumambulating) it).
The Tawaf around the House is a well-established ritual, Sa`id bin Jubayr said that,
(for those who are circumambulating it) means, strangers (he means who do not live in Makkah), while;
(or staying (I`tikaf)) is about those who live in the area of the Sacred House. Also, Qatadah and Ar-Rabi` bin Anas said that I`tikaf is in reference to those who live in the area of the House, just as Sa`id bin Jubayr stated. Allah said,
(or bowing or prostrating themselves (there, in prayer))
Ibn `Abbas said, when it is a place of prayer it includes those who are described as bowing and prostrating themselves. Also, `Ata' and Qatadah offered the same Tafsir.
Purifying all Masjids is required according to this Ayah and according to Allah's statement,
﴿فِى بُيُوتٍ أَذِنَ اللَّهُ أَن تُرْفَعَ وَيُذْكَرَ فِيهَا اسْمُهُ يُسَبِّحُ لَهُ فِيهَا بِالْغُدُوِّ وَالاٌّصَالِ ﴾
(In houses (mosques) which Allah has ordered to be raised (to be cleaned, and to be honored), in them His Name is remembered (i.e. Adhan, Iqamah, Salah, invocations, recitation of the Qur'an). Therein glorify Him (Allah) in the mornings and in the (late) afternoons) (24:36).
There are many Hadiths that give a general order for purifying the Masjids and keeping filth and impurities away from them. This is why the Prophet said,
«إِنَّمَا بُنِيَتِ الْمَسَاجِدُ لِمَا بُنِيَتْ لَه»
(The Masjids are established for the purpose that they were built for (i. e. worshipping Allah alone).)
I have collected a book on this subject, and all praise is due to Allah.