حَدَّثَنَا زُهَيْرُ بْنُ حَرْبٍ، وَمُحَمَّدُ بْنُ الْمُثَنَّى، قَالاَ حَدَّثَنَا يَحْيَى، - وَهُوَ الْقَطَّانُ - عَنْ عُبَيْدِ اللَّهِ، أَخْبَرَنِي نَافِعٌ، عَنِ ابْنِ عُمَرَ، أَنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم قَالَ ‏"‏ لاَ تُسَافِرِ الْمَرْأَةُ ثَلاَثًا إِلاَّ وَمَعَهَا ذُو مَحْرَمٍ ‏"‏ ‏.‏
Translation
Ibn 'Abbas (Allah be pleased with them) reported

I heard Allah's Messenger (ﷺ) delivering a sermon and making this observation:" No person should be alone with a woman except when there is a Mahram with her, and the woman should not undertake journey except with a Mahram." A person stood up and said: Allah's Messenger, my wife has set out for pilgrimage, whereas I am enlisted to fight in such and such battle, whereupon he said:" You go and perform Hajj with your wife."