He had made a vow during the days of ignorance to observe itikaf for one night, so he asked the Prophet ﷺ about it, and he instructed him to fulfill the itikaf.
حدثنا إسحق بن موسى الخطمي حدثنا سفيان بن عيينة عن أيوب عن نافع عن ابن عمر
أنه كان عليه نذر ليلة في الجاهلية يعتكفها فسأل النبي ﷺ فأمره أن يعتكف
Bukhari narrated it in the book of itikaf, chapter of one who did not consider fasting obligatory upon himself when observing itikaf, hadith no. 2042 and 2043, and Muslim narrated it in the book of vows, chapter on the vow of a disbeliever and what he should do about it if he becomes Muslim, hadith no. 1656, from the hadith of Nafi through the same chain.