Sahih al-Bukhari Book 33, Hadith 17
`Umar bin Al-Khattab said, "O Allah's Messenger (ﷺ)! I vowed in the Pre-Islamic period to perform I`tikaf in
Al-Masjid-al-Haram for one night." The Prophet (ﷺ) said, "Fulfill your vow." So, he performed I`tikaf for
one night.
Allah's Messenger (ﷺ) used to practice I`tikaf every year in the month of Ramadan. And after offering the morning prayer, he used to enter the place of his I`tikaf. `Aisha asked his permission to let her practice I`tikaf and he allowed her, and so she pitched a tent in the mosque. When Hafsa heard of that, she also pitched a tent (for herself), and when Zainab heard of that, she too pitched another tent. When, in the morning, Allah's Messenger (ﷺ) had finished the morning prayer, he saw four tents and asked, "What is this?" He was informed about it. He then said, "What made them do this? Is it righteousness? Remove the tents, for I do not want to see them." So, the tents were removed. The Prophet (ﷺ) did not perform I`tikaf that year in the month of Ramadan, but did it in the last ten days of Shawwal.
that `Umar had vowed in the Pre-Islamic period to perform I`tikaf in Al-Masjid-al-Haram. (A subnarrator thinks that `Umar vowed to perform I`tikaf for one night.) Allah's Messenger (ﷺ) said to `Umar, "Fulfill your vow."