Firstly: The Origin of Walking between Safa and Marwah
The source of legislation of sa`y is the walking of Hajar (peace be upon her) when Ibrahim (peace be upon him) left her with their son Isam`il (peace be upon them both) in Mecca. The food that she had finished, and she and her son began to feel thirsty. She walked between Safa and Marwah seven times looking for water. Ibn `Abbas said: “The mother of Isma`il would nurse Isma`il and drinking from the water they had until the waterskin emptied and she and her son became thirsty. Then she saw him twist – or he said turn  The Arabic word yatalabbat means to turn around on the ground. – so she set out, for she disliked to see that. She saw that Safa was the closest hill in the surrounding area, so she climbed it. She then faced the valley looking to see if she would see anyone. When she saw no one, she descended until she reached the valley upon which she lifted the edge of her garment and ran with exertion until she exited the valley. She then approached Marwah and climbed it. She looked about to see if she could see anyone but saw no one. She did this seven times.” Ibn `Abbas (may Allah be pleased with him and his father) says: “The Prophet ﷺ says: ‘And thus is how people walk between them.’”
Secondly: The Wisdom of Walking between Safa and Marwah  Al-Nawawi says: “Amongst the acts of worship whose meanings are not known are sa`y and pelting stones [at the Jamarat]. Slaves have been required to do so in order that their servitude be complete. This type of act of worship has no portion for the ego in it, nor for the mind, nor does anyone perform them except out of obeying the [Divine] command and perfecting servitude. This is a brief indication through which the wisdom behind all acts of worship may be known. And Allah knows best.” (Al-Majmu`, 8/243) Al-Shinqiti comments on this: “What Sheikh al-Nawawi says in that the wisdom behind sa`y and pelting stones is not understood is not correct from what I can see. Allah knows best. Rather, the wisdom behind pelting stones and sa`y is understood. To be sure, some texts have indicated that their meanings are known.” (Adwa’ al-Bayan, 4/480)
1. The wisdom of walking between Safa and Marwah
The legislation of walking between Safa and Marwah revives the remembrance of Ibrahim, his wife Hajar, and their son Isma`il (peace be upon them), their state of obedience to the commandment of Allah the Exalted, and their hastening to it. This reminder drives one to be likewise, and confirms their exaltation in hearts.
2. To allow slaves of Allah to feel their need and indigence before their Creator and Provider like the need and indigence of that woman at that difficult time, and like the enormous hardship with which she faced her Creator and Provider. It also allows them to remember that those who obey Allah – like Ibrahim (peace and blessings be upon him and our Prophet) – are not abandoned by Allah, and their supplication is not lost.