There are several examples of non-Muslim armies getting relatively close to Mecca, or at least threatening the Hijazi coast. However, the only example of a land invasion (that I am aware of) is that by the Abyssinian Kingdom of Aksum in 570-1 CE, which occurred before the emergence of Islam. The heterodox Shi'i Qarmatians pillaged Mecca in 930. The French Crusader Raynald de Chatillon sent raids against pilgrimage routes, which reached quite deep into the Hijaz. However, he was executed by Saladin himself in 1187. The Portuguese projected naval power into the Red Sea but were checked by a mixed Ottoman-Mamluk^1 fleet at Jidda in 1517. I'll talk about two of these examples.
The Abyssinian Invasion of the Hijaz:
According to Surat al-Fil in the Qur'an and commentary on its verses (tafsir) by Muslim scholars, Abraha al-Ashram, the Abyssinian governor of Yemen, attempted to invade Mecca and destroy the Ka'ba in 570-1 with an army that included war elephants.^2 The reason given is that he was attempting to divert trade and pilgrimage away from Mecca and towards San'a, where the Abyssinians had built a cathedral. Incidentally, the Abyssinian Kingdom of Aksum is perhaps the only example of a sub-Saharan African empire extending into Asia. Again, this narrative is according to the Islamic religious tradition, which many modern historians approach with caution. However, from what I have read this event in at least its rough outlines is generally regarded as historical.
After the emergence of the Caliphate after the death of Prophet Muhammad in 632, there soon emerged a rivalry between the nascent Islamic state and the Abyssinian kingdom over the Red Sea. The Abyssinians attacked the Hijaz and the Arabs retaliated by occupying the Dahlak islands in 702,^3 which were opposite the Abyssinian port of Adulis. The Abyssinians' control of Red Sea trade ended, "which precipitated the [Aksumite] kingdom’s decline."^4
The Portuguese in the Red Sea:
Portuguese naval activity had been present in the Red Sea in the final years of the Mamluk Sultanate, which was conquered by the Ottoman Sultan Selim "the Grim" in 1516-7. The principle maritime port of the Hijaz is Jidda, which was attacked by the Portuguese in 1517. The Ottoman admiral Selman Reis had entered Mamluk service earlier in 1515 and defended the port. His heroic efforts were under-appreciated, however, and Selim imprisoned him for joining the Mamluks. Selman Reis was freed by Ibrahim Pasa in Ottoman 1524 and later participated in anti-Portuguese naval activity in the Indian Ocean.^5
Sources:
The fleet was essentially Mamluk but was led by the Ottoman admiral Selman Reis who was accompanied by soldiers from Ottoman territory. Selman Reis had entered Mamluk service before the Ottomans and Mamluks went to war in 1516.
"Muhammad, the Prophet (571–632 CE)" by Recep Senturk in Medieval Islamic Civilization: An Encyclopedia, p. 525. Incidentally, the "Year of the Elephant" (570) was also the year the Prophet Muhammad was born.
Timothy Power, The Red Sea from Byzantium to the Caliphate: AD 500-1000, p. 93.
"Abyssinia" by Cedric Barnes in Medieval Islamic Civilization: An Encyclopedia, p. 12.
See Giancarlo Casale's The Ottoman Age of Exploration for Ottoman naval activity in the Indian Ocean.