In reality the maintenance of the Masjids is by prayer (As-Salah), acts of obedience, and I'tikaf (seclusion for devotional worship) in them, as well as other physical and verbal acts of worship. Hence, this verse is commanding those who persistently observe the acts of worship in the Masjids by various acts of drawing near to Allah. This is a testimony to the faith of these people. It has been reported in a hadith of the prophet that At-Tirmithi graded Hasan:
"If you see a man who is accustomed (to coming) to the Masjid, then testify to his faith." (At-Tirmithi no.2617)
This is proven by his verse (9:18)and for this reason it is not for the Mushrikun (polytheists, idolaters) to maintain the Masjids of Allah.
Included in this meaning is building them from good (lawful) earnings in order to seek the reward. For indeed it has been reported (in Hadiths) that which proves the virtue of building Masjids for the Face of Allah, the Most High. Concerning those who disbelieve in Allah, it does not benefit or profit them if they help with wealth in building Masjids. This is due to the nullification of their deeds by shirk (their associating partners with Allah.) However, if they (the disbelievers) build it with their wealth as charity or they share in its construction, it is permissible to pray in it.