I recited to Ayesha the verse "there is no blame on him to walk between them" and said, "I would not mind if I did not walk between them."She replied, "What a terrible thing to say! In the days of ignorance, some people refused to walk between them. When Islam came and the Quran was revealed with the verse "Indeed, Safa and Marwa are among the symbols of Allah" [Baqarah 2:158], the Messenger of Allah ﷺ walked between them and we walked with him, so it became an established practice."
أخبرنا محمد بن منصور قال حدثنا سفيان عن الزهري
قرأت على عائشة {فلا جناح عليه أن يطوف بهما} قلت ما أبالي أن لا أطوف بينهما فقالت بئسما قلت إنما كان ناس من أهل الجاهلية لا يطوفون بينهما فلما كان الإسلام ونزل القرآن {إن الصفا والمروة من شعائر الله} الآية فطاف رسول الله ﷺ وطفنا معه فكانت سنة
Sourced from Bukhari, Tafsir, chapter on "And Manat, the third one", hadith 4861, and Muslim, Hajj, chapter explaining that the sa'i between Safa and Marwa is a pillar without which Hajj is not valid, hadith 1277, from the hadith of Sufyan bin Uyayna, with this same wording.