Praise be to Allah.
I’tikaaf is prescribed according to the Qur’aan and Sunnah and scholarly consensus.
In the Qur’aan, Allaah 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)”
“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”
With regard to the Sunnah, there are many ahaadeeth, such as the hadeeth of ‘Aa’ishah (may Allaah be pleased with her) who said that the Prophet (peace and blessings of Allaah be upon him) used to observe i'tikaaf during the last ten days of Ramadaan until Allaah took his soul, then his wives observed i’tikaaf after he was gone. Narrated by al-Bukhaari, 2026; Muslim, 1172.
With regard to scholarly consensus, more than one of the scholars narrated that there was scholarly consensus that i’tikaaf is prescribed in sharee’ah, such as al-Nawawi, Ibn Qudaamah, Shaykh al-Islam Ibn Taymiyah, and others.
See al-Majmoo’, 6/404; al-Mughni, 4/456; Sharh al-‘Umdah, 2/711.
Shaykh Ibn Baaz said in Majmoo’ al-Fataawa, 15/437:
Undoubtedly i’tikaaf in the mosque is an act of worship, and (observing it) in Ramadaan is better than at other times. It is prescribed in Ramadaan 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 (peace and blessings of Allaah be upon him) said: “Whoever vows to obey Allaah, let him obey Him, and whoever vows to disobey Him, let him not disobey Him.” Narrated by al-Bukhaari, 6696.
And ‘Umar (may Allaah be pleased with him) said: “O Messenger of Allaah, during the Jaahiliyyah I vowed to observe i’tikaaf for one night in al-Masjid al-Haraam.” He said: “Fulfil your vow.” (6697).
Ibn al-Mundhir said in his book al-Ijmaa’ (p. 53):
They were unanimously agreed that i’tikaaf is Sunnah and is not obligatory unless a man obliges himself to do that by making a vow, in which case it becomes obligatory for him.
See Fiqh al-I’tikaaf by Dr Khaalid al-Mushayqih, p. 31.