Praise be to Allah.
I’tikaf in the Quran
I’tikaf is prescribed according to the Quran and Sunnah and scholarly consensus.
In the Quran, Allah says (interpretation of the meaning):
“and We commanded Ibrahim (Abraham) and Isma’il (Ishmael) that they should purify My House (the Ka‘bah at Makkah) for those who are circumambulating it, or staying (I’tikaf), 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‘tikaf (i.e. confining oneself in a mosque for prayers and invocations leaving the worldly activities) in the mosques.” [al-Baqarah 2:187]
I’tikaf in the Sunnah
With regard to the Sunnah, there are many ahadith, such as the hadith of ‘Aishah (may Allah be pleased with her) who said that the Prophet (peace and blessings of Allah be upon him) used to observe i'tikaf during the last ten days of Ramadan until Allah took his soul, then his wives observed i'tikaf after he was gone. Narrated by al-Bukhari, 2026; Muslim, 1172.
I’tikaf according to scholarly consensus
With regard to scholarly consensus, more than one of the scholars narrated that there was scholarly consensus that i’tikaf is prescribed in shari’ah, such as al-Nawawi, Ibn Qudamah, Shaykh al-Islam Ibn Taymiyah, and others. (See al-Majmu’, 6/404; al-Mughni, 4/456; Sharh al-‘Umdah, 2/711)
Shaykh Ibn Baz said in Majmu’ al-Fatawa, 15/437:
“Undoubtedly i'tikaf 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.”
Is I’tikaf Compulsory?
The basic principle is that i’tikaf is Sunnah, not obligatory, unless one made a vow to do it, in which case it becomes obligatory. This is because the Prophet (peace and blessings of Allah be upon him) said: “Whoever vows to obey Allah, let him obey Him, and whoever vows to disobey Him, let him not disobey Him.” (Narrated by al-Bukhari, 6696.)
And ‘Umar (may Allah be pleased with him) said: “O Messenger of Allah, during the Jahiliyyah I vowed to observe i’tikaf for one night in al-Masjid al-Haram.” He said: “Fulfill your vow.” (6697)
Ibn al-Mundhir said in his book al-Ijma' (p. 53):
“They unanimously agreed that i’tikaf 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’tikaf by Dr Khalid al-Mushayqih, p. 31)
And Allah knows best.