Narrated 'Umar (RA):
[concerning his consultation with the Prophet] He said: I said: O Allah's Messenger (ﷺ), I made a vow in the Jahiliyya times to spend a night in devotion (I'tikaf) in the Sacred Mosque. He (the Prophet) said: "Fulfill your vow."[Agreed upon]. al-Bukhari added in another narration: "Then, spend a night in devotion (in the Sacred Mosque)."
Reference: Bulugh al-Maram 1396
In-book reference: Book 13, Hadith 23
English translation: Book 13, Hadith 1396