The following hadith by the prophet provides the background of how Makkah and Kaa’ba came into existence. Narrated Ibn ‘Abbâs [On the authority of the Prophet (See Fath Al-Bari, Vol. 7, Page 210)].
“…(Prophet) Ibrâhîm (Abraham) brought her (Hajar) and her son Ismail (Ishmael) while she used to nurse him at her breast, near the Ka‘bah under a tree on the spot of Zamzam, at the highest place in the mosque. During those days there was nobody in Makkah, nor was there any water. So he made them sit over there and placed near them a leather bag containing some dates, and a small water-skin containing some water, and set out homeward. Ismail’s (Ishmael) mother followed him saying, “O Ibrâhîm (Abraham)! Where are you going, leaving us in this valley where there is no person whose company we may enjoy, nor is there anything (to enjoy)?” She repeated that to him many times, but he did not look back at her. Then she asked him, “Has Allâh ordered you to do so?” He said, “Yes.” She said, “Then He will not neglect us,” and returned while Ibrâhîm (Abraham) proceeded onwards, and on reaching the Thaniyyah where they could not see him, he faced the Ka‘bah, and raising both hands invoked Allâh saying the following supplication:
‘O our Lord! I have made some of my offspring to dwell in an uncultivable valley by Your Sacred House (the Ka‘bah at Makkah); in order, O our Lord, that they may perform As-Salât (Iqâmat-as-Salât). So fill some hearts among men with love towards them, and (O Allâh) provide them with fruits, so that they may give thanks.’ (V.14:37)
Ismail’s (Ishmael) mother went on suckling Ismail (Ishmael) and drinking from the water (she had). When the water in the water-skin had all been used up, she became thirsty and her child also became thirsty. She started looking at him [i.e. Ismail (Ishmael)] tossing in agony; she left him, for she could not endure looking at him, and found that the mountain of As-Safâ was the nearest mountain to her on that land. She stood on it and started looking at the valley keenly so that she might see somebody, but she could not see anybody. Then she descended from As-Safâ and when she reached the valley, she tucked up her robe and ran in the valley like a person in distress and trouble, till she crossed the valley and reached Al-Marwah mountain where she stood and started looking, expecting to see somebody, but she could not see anybody. She repeated that (running between As-Safâ and Al-Marwah) seven times.”The Prophet said, “This is the source of the tradition of the Sa‘y (the going) of people between them (i.e. As-Safâ and Al-Marwah). When she reached Al-Marwah (for the last time) she heard a voice and she asked herself to be quiet and listened attentively. She heard the voice again and said, ‘O (whoever you may be)! You have made me hear your voice; have you got something to help me?’ And behold! She saw an angel at the place of Zamzam, digging the earth with his heel (or his wing), till water flowed from that place. She started to make something like a basin around it, using her hands in this way and started filling her water-skin with water with her hands, and the water was flowing out after she had scooped some of it.”The Prophet added, “May Allâh bestow mercy on Ismail’s (Ishmael) mother! Had she let the Zamzam (flow without trying to control it) (or had she not scooped from that water) (to fill her water-skin), Zamzam would have been a stream flowing on the surface of the earth.”The Prophet further added, “Then she drank (water) and suckled her child. The angel said to her, ‘Don’t be afraid of being neglected, for this is the House of Allâh which will be built by this boy and his father, and Allâh never neglects His people.’
The House (i.e. Ka‘bah) at that time was on a high place resembling a hillock, and when torrents came, they flowed to its right and left. She lived in that way till some people from the tribe of Jurhum or a family from Jurhum passed by her and her child, as they (i.e. the Jurhum people) were coming through the way of Kadâ’. They landed in the lower part of Makkah where they saw a bird that had the habit of flying around water and not leaving it. They said, ‘This bird must be flying around water, though we know that there is no water in this valley.’ They sent one or two messengers who discovered the source of water, and returned to inform them of the water. So, they all came (towards the water).”The Prophet added, “Ismail’s (Ishmael) mother was sitting near the water. They asked her, ‘Do you allow us to stay with you?’ She replied, ‘Yes, but you will have no right to possess the water.’ They agreed to that.”The Prophet further said, “Ismail’s (Ishmael) mother was pleased with the whole situation as she used to love to enjoy the company of the people. So, they settled there, and later on they sent for their families who came and settled with them so that some families became permanent residents there. The child [i.e. Ismail (Ishmael)] grew up and learned Arabic from them and (his virtues) caused them to love and admire him as he grew up, and when he reached the age of puberty they made him marry a woman from amongst them.
After Ismail’s (Ishmael) mother had died, Ibrâhîm (Abraham) came after Ismail’s (Ishmael) marriage in order to see his family that he had left before, but he did not find Ismail (Ishmael) there. When he asked Ismail’s (Ishmael) wife about him, she replied, ‘He has gone in search of our livelihood.’ Then he asked her about their way of living and their condition, and she replied, ‘We are living in misery; we are living in hardship and destitution,’ complaining to him. He said, ‘When your husband returns, convey my salutation to him and tell him to change the threshold of the gate (of his house).’ When Ismail (Ishmael) came, he seemed to have felt something unusual, so he asked his wife, ‘Has anyone visited you?’ She replied, ‘Yes, an old man of such and such description came and asked me about you and I informed him, and he asked about our state of living, and I told him that we were living in a hardship and poverty.’ On that Ismail (Ishmael) said, ‘Did he advise you anything?’ She replied, ‘Yes, he told me to convey his salutation to you and to tell you to change the threshold of your gate.’ Ismail (Ishmael) said, ‘It was my father, and he has ordered me to divorce you. Go back to your family.’ So, Ismail (Ishmael) divorced her and married another woman from amongst them (i.e. Jurhum).
Then Ibrâhîm (Abraham) stayed away from them for a period as long as Allâh wished and called on them again but did not find Ismail (Ishmael). So he came to Ismail’s (Ishmael) wife and asked her about Ismail (Ishmael). She said, ‘He has gone in search of our livelihood.’ Ibrâhîm (Abraham) asked her, ‘How are you getting on?’ asking her about their sustenance and living. She replied, ‘We are prosperous and well-off (i.e. we have everything in abundance).’ Then she thanked Allâh?? ??? Ibrâhîm (Abraham) said, ‘What kind of food do you eat?’ She said, ‘Meat.’ He said, ‘What do you drink?’ She said, ‘Water.’ He said, ‘O Allâh! Bless their meat and water.’ “The Prophet added, “At that time they did not have grain, and if they had grain, he would have also invoked Allâh to bless it.”The Prophet added, “If somebody has only these two things as his sustenance, his health and disposition will be badly affected, unless he lives in Makkah.” The Prophet added, “Then Ibrâhîm (Abraham) said to Ismail’s (Ishmael) wife, ‘When your husband comes, give my regards to him and tell him that he should keep firm the threshold of his gate.’ When Ismail (Ishmael) came back, he asked his wife, ‘Did anyone call on you?’ She replied, ‘Yes, a good-looking old man came to me,’ so she praised him and added. ‘He asked about you, and I informed him, and he asked about our livelihood and I told him that we were in a good condition.’ Ismail (Ishmael) asked her, ‘Did he give you any piece of advice?’ She said, ‘Yes, he told me to give his regards to you and ordered that you should keep firm the threshold of your gate.’ On that Ismail (Ishmael) said, ‘It was my father, and you are the threshold (of the gate). He has ordered me to keep you with me.’
Then Ibrâhîm (Abraham) stayed away from them for a period as long as Allâh wished, and called on them afterwards. He saw Ismail (Ishmael) under a tree near Zamzam, sharpening his arrows. When he saw Ibrâhîm (Abraham), he rose up to welcome him (and they greeted each other as a father does with his son or a son does with his father). Ibrâhîm (Abraham) said, ‘O Ismail (Ishmael)! Allâh has given me an order.’ Ismail (Ishmael) said, ‘Do what your Lord has ordered you to do.’ Ibrâhîm (Abraham) asked, ‘Will you help me?’ Ismail (Ishmael) said, ‘I will help you.’ Ibrâhîm (Abraham) said, ‘Allâh has ordered me to build a house here,’ pointing to a hillock higher than the land surrounding it.’”The Prophet added, “Then they raised the foundations of the House (i.e. the Ka‘bah). Ismail (Ishmael) brought the stones and Ibrâhîm (Abraham) was building; and when the walls became high, Ismail (Ishmael) brought this stone and put it for Ibrâhîm (Abraham) who stood over it and carried on building, while Ismail (Ishmael) was handing him the stones, and both of them were saying,
‘O our Lord! Accept (this service) from us. Verily, You are the All-Hearer the All-Knower.’” (V.2:127).
The Prophet added, “Then both of them went on building and going round the Ka‘bah saying ‘O our Lord! Accept (this service) from us. Verily, You are the All-Hearer, the All-Knower.’” (V.2:127) [Sahih Al-Bukhari, Vol.4, Hadith No.583].