I heard the Prophet ﷺ saying in a sermon, "No man should be alone with a woman unless a Muharram relative of hers is present, and a woman must not travel except with a Muharram relative."A man stood up and said, "Messenger of Allah, my wife has set out for Hajj, and I have been enlisted for such-and-such military expedition."He replied, "Go and perform Hajj with your wife."
سمعت النبي ﷺ يخطب يقول: لا يخلون رجل بامرأة إلا ومعها ذو محرم، ولا تسافر المرأة إلا مع ذي محرم. فقام رجل فقال: يا رسول الله، إن امرأتي خرجت حاجة، وإني اكتتبت في غزوة كذا وكذا. قال: انطلق فحج مع امرأتك
Bukhari narrated it in the Book of Marriage (5233), and Muslim in the Book of Hajj (1314), both through Sufyan bin Uyayna, who said, Amr bin Dinar related to us, from Abu Mabad, who said, I heard Ibn Abbas say... and he mentioned it. The wording given here follows Muslim's version.