Almighty Allah says in the Holy Quran:
‘Itikaaf literally means committing oneself to stay put in a place. In the terminology of the Shariah, it means to stay day and night in a mosque while fasting with the intention of worship. There are 3 types of ‘Itikaaf, Compulsory (Wajib), Sunnah and Nafl (supererogatory).
Compulsory ‘Itikaaf is when someone takes an oath to perform ‘Itikaaf for a set number of days, etc. and thus makes it Compulsory upon himself (or herself).
Sunnah ‘Itikaaf is to perform ‘Itikaaf for the last 10 days of Ramadhan. This is Sunnah Moukkada Kifayah. If no one from the locality performs ‘Itikaaf in the local mosque, then everybody will be held accountable for it.
Apart from the aforementioned two situations, any time someone stays in a mosque, it is Commendable (Mustahab) ‘Itikaaf. The minimum time period for this is a moment (1 Sa’aah). Even in this, it is better that one fasts and if one is performing Supererogatory ‘Itikaaf for one day and one night, then it is highly reasonable that one should fast as well.
‘Itikaaf is permissible only in a mosque where all the 5 daily Salaat are offered. The most excellence place for ‘Itikaaf is in Masjid Haraam i.e. the Ka’aba, then Masjid Nabawi, the Prophet’s mosque.
Fasting is a necessary condition even for the Compulsory ‘Itikaaf that is performed in months other than Ramadhan. It is not permissible for the person performing the ‘Itikaaf to leave the mosque except for those things that are unavoidable like for relieving oneself or to get food from the house when one is forced to or to go to the grand mosque for Friday Salaat. However, it is not permissible to stay/wait one the road or in the house.
If a woman wants to perform ‘Itikaaf, it is permissible for her to do so at that place in the house which is reserved for offering Salaat. If the menses start while in ‘Itikaaf, she should abandon her ‘Itikaaf.
Having sex or kissing one’s spouse while performing ‘Itikaaf is not permissible. (Hidayah, Fatawa A’alamgiri, Radd Ul Muhtaar, Bayaan Ul Qaraain
…And refrain from having sexual contact with your wives, whilst you are in ‘Itikaaf in the mosques… Surah Baqarah (2:187)