Translation:

17. It is not for such as join gods with Allah to visit or maintain the mosques of Allah while they witness against their own souls to infidelity. The works of such bear no fruit: in fire shall they dwell.

Notes (Tafseer)

1266. 'Amara as applied to mosques implies the following ideas: (1) to build or repair: (2) to maintain in fitting dignity: (3) to visit for purposes of devotion: and (4) fill with light and life and activity. For brevity I have only used "maintain" in the Translation. Before the preaching of Islam the Pagans built, repaired, and maintained the Mosque, and celebrated Pagan ceremonies in it. They made an income out of it. Islam protested, and the Pagans ejected Muslims and their Leader from Makkah and shut them out from the Ka'ba itself. When the Muslims were strong enough to re-take Makkah (A.H. 8), they purified the Mosque and re-established the worship of the true God. If they became Muslims, it was a different matter. The further question arose: should they be allowed to visit it and practise their unseemly Pagan rites? Obviously this would be derogatory to the dignity and honour of the Mosque, and was forbidden. This was the particular occasion to which the verse refers. The general deduction is clear. A house of Allah is a place of sincere devotion, not a theatre for vulgar rites nor a source of worldly income. Only sincere Believers have a right of entry. Who the sincere Believers are, is explained in the next verse.