I heard the Messenger of Allah ﷺ say, "A woman must not travel for two days unless accompanied by her husband or a close male relative."
سمعت رسول الله ﷺ يقول: لا تسافر المرأة يومين إلا ومعها زوجها أو ذو محرم.
Bukhari narrated it in the chapter on the merit of prayer in the masjid of Makkah and Madinah (1197), and Muslim in the Hajj chapter (827:416), both from the hadith of Shubah and others, from Abdul-Malik bin Umayr, from Qazaah, from Abu Saeed, within a longer account. See "What has been said about the masjids to which journeys may be undertaken." Muslim also narrated it (1340:423) through the route of Amash, from Abu Salih, from Abu Saeed Khudri, who said, the Messenger of Allah ﷺ said, "It is not permissible for a woman who believes in Allah and the Last Day to travel a journey of three days or more unless her father, her son, her husband, her brother, or a mahram relative of hers is with her."