He said, "Messenger of Allah, I vowed during the days of ignorance to spend a night in spiritual retreat in the Sacred Mosque."The Prophet ﷺ said to him, "Fulfill your vow."
أحمد بن حنبل حدثنا يحيى عن عبيد الله حدثني نافع عن ابن عمر
أنه قال يا رسول الله إني نذرت في الجاهلية أن أعتكف في المسجد الحرام ليلة فقال له النبي ﷺ أوف بنذرك
Bukhari, Itikaf, Chapter on itikaf at night, no. 2032, and Muslim, Oaths, Chapter on the vow of a disbeliever and what he should do about it when he becomes Muslim, no. 1656, from the hadith of Yahya Qattan through this route, and it is in Musnad Ahmad, 1/37.