I’tikaaf (Confining oneself in a Masjid for Worship)
Aa’isha (radi Allahu anha) said that the Prophet (sal Allahu alaihi wa sallam) used to observe i’tikaaf during the last ten days of Ramadan until Allah took his soul, then his wives observed i’tikaaf after he was gone.
[Sahih al-Bukhari and Muslim]
I’tikaaf is prescribed according to the Qur’an and Sunnah and scholarly consensus (ijma).
In the Qur’an, Allah says (interpretation of the meaning): “And We commanded Ibraaheem (Abraham) and Ismaa’eel (Ishmael) that they should purify My House (the Ka‘bah at Makkah) for those who are circumambulating it, or staying (I’tikaaf), or bowing or prostrating themselves (there, in prayer)” [Al-Baqarah 2:125]
“And do not have sexual relations with them (your wives) while you are in I‘tikaaf (i.e. confining oneself in a mosque for prayers and invocations leaving the worldly activities) in the mosques” [Al-Baqarah 2:187]
With regard to the Sunnah, there are many ahadith, such as the above narration of Aa’isha(radi Allahu anha).
With regard to scholarly consensus, more than one of the scholars narrated that there was scholarly consensus (ijma) that i’tikaaf is prescribed in the sharee’ah, such as Imam al-Nawawi, Ibn Qudaamah, Shaykh al-Islam Ibn Taymiyah, and others (may Allah have mercy upon them all).
Shaykh Ibn Baaz (may Allah have mercy upon him) said in ‘Majmoo’ al-Fataawa’: “Undoubtedly i’tikaaf in the mosque is an act of worship, and (observing it) in Ramadan is better than at other times. It is prescribed in Ramadan and at other times.”
The ruling on i’tikaaf:
The basic principle is that i’tikaaf is Sunnah, not obligatory, unless one made a vow to do it, in which case it becomes obligatory, because the Prophet (sal Allahu alaihi wa sallam) said: “Whoever vows to obey Allah, let him obey Him, and whoever vows to disobey Him, let him not disobey Him.” [Sahih al-Bukhari]
And ‘Umar (radi Allahu anhu) said: “O Messenger of Allah, during the Jaahiliyyah (pre-Islamic times of ignorance) I vowed to observe i’tikaaf for one night in al-Masjid al-Haraam.” He (sal Allahu alaihi wa sallam) said: “Fulfil your vow.” [Sahih al-Bukhari and Muslim]
And Allah knows best!