OK, here is something interesting I have found.
By Justice Maulana Muhammad Taqi Usmani
The Entry Of Non-Muslims In Makkah And Madinah
Q. "Non-Muslims are not allowed to enter the city limits of Makkah Mukarramah and Madinah Munawwarah. The entry of non-Muslims in the Haram limits of Makkah was banned in 9th Hijrah by a Quranic order contained in the Surah al-Bar'ah, verse 27.
Did this order apply to the Haram of Makkah only or also to the Haram of Madinah? The Qur'an does not say so.
Imam Malik and Umar bin Abdul-Aziz etc. Interpreted the verse to apply to all the masjids.
There is one Hadith in which the arabian peninsula has been banned for non-Muslims, but the Haram of Madinah remained open to non-Muslims during the lifetime of Rasoolullah( Sallaho Alaihai Wasallam ) and also after him Madinah was the Capital of the Islamic state and the ambassadors and the foreign delegations used to visit the city.
Upto what time the city of Madinah remained open for non-Muslims and since what time it was banned for them and on what authority? Does the verse of Surah al-Bara'ah include the city of Madinah?
Your reply will be a source of guidance." (A. S. Navlwala, Karachi)
A. There are three different injunctions in relation to the entry of non-Muslims into Arabia which should be understood sapa- rately, and should not be confused with each other :
The first injunction is found in the well-known Hadith:
Expel the mushriks from the Arabian peninsula (Bukhari)
All the Muslim jurists are unanimous on the point that this Hadith has banned the permanent citizenship of the Arabian pe- ninsula for the mushriks but has not prohibited their entry on their temporary visit to the peninsula. They may enter the pe- ninsula and stay there for some time but they cannot live there as its permanent citizens. In other words, the Arabian peninsula has been declared as a homeland for Muslims exclusively. So, if the foreign visitors or envoys or delegations have been allowed to enter the peninsula, it was, by no means, a contravention of the instruction of the Hadith quoted above.
The second injunction relates to the entry of the non-Muslims into the precincts of the Haram of Makkah. This injunction is based on Quranic verse contained in the Surah al-Bara'ah :
The Associators are impure. So they must not come near "Almasjid al-Haram" the Holy Mosque of Makkah.
But the Muslim jurists are not unanimous in the interpretation of this verse. Their different views are as follows :
1.
According to the view of Imam Ahmed bin Hanbal and Imam Shafi'i this verse has banned the entry of the non- Muslims not only to the Holy Mosque, but also to the whole precincts of Haram including the city of Makkah.
2.
Imam Malik extends this prohibition to all the masjids of the world. He says that the prohibition is based on the impu- rity of the non-Muslims and every masjid in every part of the world deserves to be immune from such impurity.
3.
Imam Abu Hanifah interprets the verse in a quite different way. He says that it is not the non-Muslims that has been banned by this verse, but the context of the verse suggests that the non-Muslims have been forbidden from performing Hajj and Umrah. Before the revelation of this verse, the pagans of Arabia used to perform Hajj and Umrah. Even in the 9th year after Hijrah, when Abu Bakr (R.A) was made the leader of the Hajj a large number of the pagans of Arabia perf- ormed Hajj with him.
On this occasion the Surah of Bara'ah was revealed and their Hajj and Umrah was totally banned with effect from the next year. The Holy Prophet ( Sallaho Alaihai Wasallam ) sent Sayyidna 'Ali (R.A) to announce his prohibition in the plain of 'Arafat where he conveyed the injunctions of the Surah al-Bara'ah to all present in that Hajj. On that occasion he did not announce that the non-Muslims cannot enter the Holy Mosque after his year. Instead, he announced :
"No Associator shall perform Hajj after this year." Keeping in view the context of the verse of Surah al-Bara'ah and this historical background, Imam Abu Hanifah has not taken the verse as a prohibition against the entry of non-Muslims into the limits of Haram or into the Holy Mosque, but has confined the prohibition to the performance of Hajj or Umrah only. It means that the non-Muslims cannot.
Source:
Miscellaneous