﴿مَا كَانَ لِلْمُشْرِكِينَ أَن يَعْمُرُوا مَسَاجِدَ الله شَاهِدِينَ عَلَى أَنفُسِهِمْ بِالْكُفْرِ أُوْلَئِكَ حَبِطَتْ أَعْمَالُهُمْ وَفِي النَّارِ هُمْ خَالِدُونَ﴾ [التوبة: 17]
17 - It is not proper for polytheists to visit masjids which have been built for the sake of Allah while they bear witness against themselves that they disbelieve in that which was sent down to Muhammad (peace be upon him). They associate partners with Allah by saying: Here I am responding to You, you have no partners except one whom You own without owning You. Glory be to Him, the actions of those people were null and void because of their disbelief, and their punishment shall be torture in Hell forever.
﴿إِنَّمَا يَعْمُرُ مَسَاجِدَ اللّهِ مَنْ آمَنَ بِاللّهِ وَالْيَوْمِ الآخِرِ وَأَقَامَ الصَّلاَةَ وَآتَى الزَّكَاةَ وَلَمْ يَخْشَ إِلاَّ اللّهَ فَعَسَى أُوْلَئِكَ أَن يَكُونُوا مِنَ الْمُهْتَدِينَ﴾ [التوبة: 18]
18 - The Mosques of Allah shall be maintained only by those who believe in Allah alone and in the Day of Recompense and its reward and punishment, perform As-Salat as Allah ordained, give Zakah from the due money, and fear none but Allah by not worshipping others except Him. Those are the people who walk on the way of truth and who will win Paradise.
﴿أَجَعَلْتُمْ سِقَايَةَ الْحَاجِّ وَعِمَارَةَ الْمَسْجِدِ الْحَرَامِ كَمَنْ آمَنَ بِاللّهِ وَالْيَوْمِ الآخِرِ وَجَاهَدَ فِي سَبِيلِ اللّهِ لاَ يَسْتَوُونَ عِندَ اللّهِ وَاللّهُ لاَ يَهْدِي الْقَوْمَ الظَّالِمِينَ﴾ [التوبة: 19]
19 - Do you consider the providing of drinking water for the pilgrims and the maintenance of Al-Masjid al-Haram (at Makkah) as equal to the one who believes in Allah and the Last Day, and strives hard and fights in the Cause of Allah? They are not equal before Allah? The latter is better despite the virtue of the first. Verily, Allah (Glory be to Him) does not guide those who indulge in error and insist on mistakes.
Some Companions spoke about this issue, therefore the Ayah was revealed and explained that Jihad is better as was reported in Sahih Muslim.
﴿الَّذِينَ آمَنُوا وَهَاجَرُوا وَجَاهَدُوا فِي سَبِيلِ اللّهِ بِأَمْوَالِهِمْ وَأَنفُسِهِمْ أَعْظَمُ دَرَجَةً عِندَ اللّهِ وَأُوْلَئِكَ هُمُ الْفَائِزُونَ﴾ [التوبة: 20]
20 - Indeed those who believed in Allah without associating partners with Him in worship, spent their money to support His Religion, and gave their lives for His Sake shall have a greater degree and shall be of higher status at Allah than those who boasted of any other actions and preferred providing drinking water and maintaining Al-Masjid Al-Haram. Those people have obtained good and higher degrees.
﴿يُبَشِّرُهُمْ رَبُّهُم بِرَحْمَةٍ مِّنْهُ وَرِضْوَانٍ وَجَنَّاتٍ لَّهُمْ فِيهَا نَعِيمٌ مُّقِيمٌ﴾ [التوبة: 21]
21 - Those people shall have a great merit which is: Their Lord shall give them glad tiding on the Day of great horror with mercy, security, pardon, and high gardens in which there is an everlasting bliss of all things that their souls desire and gladden their eyes.
﴿خَالِدِينَ فِيهَا أَبَداً إِنَّ اللّهَ عِندَهُ أَجْرٌ عَظِيمٌ﴾ [التوبة: 22]
With a permanent eternity in these outstanding Paradises. Indeed, Allah is All-Encompassing [in favor] and Generous who doubles the rewards of good actions and saves good rewards and gifts for His Believing Servants.