He set out for Hajj with the Messenger of Allah ﷺ during the Farewell Pilgrimage, accompanied by his wife Asma bint Umays al-Khathamiyyah. When they reached Dhul-Hulayfah, Asma gave birth to Muhammad bin Abu Bakr. Abu Bakr came to the Prophet ﷺ and informed him, and the Messenger of Allah ﷺ instructed him to tell her to perform a ritual bath, then enter the state of ihram for Hajj and do everything the other pilgrims do, except that she should not perform tawaf around the Kabah.
أخبرني أحمد بن فضالة بن إبراهيم النسائي قال حدثنا خالد بن مخلد قال حدثني سليمان بن بلال قال حدثني يحيى وهو ابن سعيد الأنصاري قال سمعت القاسم بن محمد يحدث عن أبيه
أنه خرج حاجا مع رسول الله ﷺ حجة الوداع ومعه امرأته أسماء بنت عميس الخثعمية فلما كانوا بذي الحليفة ولدت أسماء محمد بن أبي بكر فأتى أبو بكر النبي ﷺ فأخبره فأمره رسول الله ﷺ أن يأمرها أن تغتسل ثم تهل بالحج وتصنع ما يصنع الناس إلا أنها لا تطوف بالبيت
Sourcing, its isnad is sahih. Ibn Majah narrated it in the chapters on Hajj, the chapter on the postpartum woman and the menstruating woman entering the state of ihram for Hajj, hadith 2912, from the hadith of Khalid bin Mukhlad, with this wording, and it is also in al-Kubra, hadith 3644. Ibn Khuzayma graded it sahih, 4/167-168, hadith 2610, and the hadith has other routes of transmission as well.