In every country there are places where not everyone can go such as to the House of Parliament in the UK or the White House in the US. There are also other places with restrictions such as special student campuses where not everyone can go and this can be for various reasons such as not being authorised to enter, for security purposes and more. Likewise, the cities of Makkah and Medina are the two holiest cities in Islam and the main centres for the religion so not everyone can enter.
There are actually places that not everyone can enter such as various religious sites. For example, in India there are about 9 Hindu temples that no non-Hindus are allowed to enter. You can read about this from here:
This is in one country. Compare this to the two cities of Makkah and Medina, which are two cities in over 22 Muslim countries.
From a logistical point of view, there are over 1.7 billion Muslims all over the world including many who are eager to go to these cities so it is not possible to accommodate all of them -already catering for over 4 million pilgrims every year is very difficult. Therefore, numbers of visitors have been restricted and many people have put their names on waiting lists, having to wait many years to visit and sometimes still do not get the chance even when they are old. If for example non Muslims could visit, it would reduce the number of Muslim visitors and it would be an injustice against those who have been waiting for so long.
***Was this answer useful to you? If so, please share with others so that they can also benefit. Feel free to provide me with any feedback so that I can try and improve. Thank you***