History of al-Haramayn al-Sharifayn
When the Prophet came to al‑Madinah after the migration, the first thing that he built there was the mosque. Afterwards he built the houses by its side. At first its area was 30 by 35 metres, which the Prophet (S) extended, making it 57 by 50 metres.
There was no minbar in the mosque at the time of its making. The Prophet (s) used to deliver his sermons leaning against one of the pillars, which were made of trunks of date‑palms. Later, the Companions built a wooden minbar with two steps. `Umar ibn al‑Khattab, during his reign, extended the mosque by five metres on southern and western sides and fifteen on the northern. He left untouched the eastern side where the dwellings of the Prophet's wives were situated.
`Uthman ibn `Affan demolished the mosque and rebuilt it, extending it in area by an amount almost equal to the one before by `Umar and left the houses of the Prophet's wives untouched. The building remained as `Uthman had made it until al‑Walid ibn `Abd al‑Malik demolished it again and extended it on all sides, and including even the houses of the Prophet's wives, together with that of `A'ishah, thus making the Prophet's tomb a part of the mosque.
The building constructed by al‑Walid stood until 266/879 when al‑Mahdi, the `Abbasid caliph, greatly extended its northern side. The building endured until the year 654/1256 when a fire broke out bringing down the roof and burning doors and the Prophet's minbar. The Mamluk sultan al‑Zahir rukn al‑Din Baybars I (658‑‑676/1260‑1277) ordered its reconstruction and the mosque was restored to its original form before the fire.
In 886/1481, lightening struck the mosque destroying all the building except the chamber of the Prophet's tomb and a dome in the mosque's courtyard. It was rebuilt by the Mamluk king al‑'Ashraf Sayf al‑Din Qait Bay (872‑‑901/1467‑‑95) in a fashion better than before. In the 10th/16th century the Ottoman sultan Salim had it renovated, building the mihrab (niche) on the western side of the minbar and which is still there.
In the 13th/19th century the Ottoman sultan Mahmud II (1223‑‑1255/1808‑‑1839) had the green dome constructed. During the same century the mosque again needed repairs, which were carried out by the orders of the Ottoman sultan. This time, the engineers dismantled the old building little by little gradually building in its place the new structure which was completed in 1277/1861.
`It is the first temple ever to be built for men, a blessed place a beacon for the nations' (3:96) and the most ancient of them in the Middle East. It was first built by Ibrahim, the ancestor of the prophets, and Isma'il, his son, and the Qur'an quotes them praying as they raised its walls:
وَإِذْ يَرْفَعُ إِبْرَاهِيمُ الْقَوَاعِدَ مِنَ الْبَيْتِ وَإِسْمَاعِيلُ رَبَّنَا تَقَبَّلْ مِنَّا إِنَّكَ أَنْتَ السَّمِيعُ الْعَلِيمُ
And when Ibrahim and Isma'il raised up the foundations of the House (and dedicated it, saying): `Our Lord, accept this from us; Thou hear all and know all'. (2:127)
Isma'il gathered the stones and Ibrahim put them on one another until the walls were raised to the height of a man. Then the Black Stone was put in its place. According to tradition, the Ka'bah (al‑Bayt al‑Atiq) was nine cubits high and had an area of twenty by thirty cubits when Ibrahim (`a) built it. It had two doors, but was without a roof.
As to the Black Stone, it is said to have been brought by Gabriel from heaven. It is also said that Adam brought it along with him on his descent from Paradise, that at first it was snow‑white and was blackened by the deeds of men, and so on. There is no harm in not believing any of these stories and the like, nor are we obliged to establish their verity, nor to know the origin of the Stone. All we are obliged to do is to revere it because the Prophet (s) considered it sacred and revered it. If someone asks the secret behind the Prophet's regarding this stone as sacred, all we can say is that only God and His Apostle know best.
According to some traditions the Ka'bah stood as Ibrahim and Isma`il had built it until it was rebuilt by Qusayy ibn Kilab, the fifth ancestor of the Prophet (s). The structure built by Qusayy stood until the time when the Prophet was 35 years old, when a great flood demolished its walls. The Quraysh rebuilt it. When the walls were raised to a man's height the clans disputed as to who should receive the honour of lifting the Black Stone into its place. They almost came to war with one another, if it was not for their making Muhammad the arbiter amongst themselves.
The Prophet's solution was to spread a cloak on the ground. Then taking up the Black Stone he laid it on the middle of the garment. "Let the eldest of each clan take hold of the border of the cloak," he said. "Then lift it up, all of you together." When they had raised it to the right height, he took the Stone and placed it in the corner with his own hands.
May God's benedictions and His mercy be upon you, O Apostle of God! You raised the Stone first with your noble hands from the ground and then put it into its place again with your hands. Thus you made God and man well pleased with you. This event was a definite evidence of your superiority over all, and of your being a `mercy for all the worlds', before your declaration of the apostlehood as after it. Your act was a clear sign that you were the bearer of a Divine mission, and that those who rejected you were enemies and opponents of the truth and of humanity.
The Ka'bah remained in its condition until Yazid ibn Mu'awiyah became caliph and till `Abd Allah ibn al‑Zubayr challenged his sovereignty over the Hijaz. Yazid's forces installed catapults on the hills around Makkah and bombarded the Ka'bah with tens of thousands of stones. The Ka'bah caught fire which finally demolished its structure. Ibn al‑Zubayr repaired it as it was before without making any changes, and he put a wooden fence around it. When `Abd al‑Malik ibn Marwan came to power, Ibn al‑Zubayr was besieged by his forces under al‑Hajjaj ibn Yusuf, who ultimately killed Ibn al‑Zubayr after causing damage to a part of the Ka'bah. Al‑Hajjaj rebuilt the demolished portions and made some changes in the walls as they used to be, and also had one of its doors (the `western door') blocked.
The Ka'bah remained in the altered condition after al‑Hajjaj's repairs until the year 1040/1630 when its walls collapsed due to heavy rains. Thereafter the Muslims from every corner gathered together to restore it and collected contributions from various regions of the Muslim world to rebuild it in the form as it stands to this day.