When a nazr (oath) is made and fulfilled. For instance, a person makes intention that if such and such thing is done then I will stay in mosque for one day or two days. In this given situation as soon as the desired work is completed Itikaf becomes vajib on him.
It should be noted that fasting (rozah) is a prerequisite for vajib e‘tikaf. Without fasting vajib e‘tikaf is incorrect.
Itikaf sunnat-e muakkadah:
Itikaf to be performed in the last third of Ramazan (i.e. last ten days in the month of Ramazan) is sunnat-e muakkadah. Performer of this Itikaf will have to enter mosque from sunset of 20th Ramadan with the niyyat of Itikaf and will have to remain in the mosque until 30th sunset (or 29th sunset if moon is seen).
This Itikaf is sunnat-e kifayah. If one person within the community performs it, the responsibility from the whole community of that area is over. If no one performs it then all (whole community) of that particular area will be held responsible.
Fasting is a condition for this e‘tikaf but the Ramazan fasts are sufficient.
Except for the Itikaf vajib and sunnat any other Itikaf would come in the category of mustahab.
Fasting is not a prerequisite for this sort of Itikaf. This sort of Itikaf can be performed by a person going to mosque/ masjid even for a short while. Simply he has to make intention of mustahab e‘tikaf for Allah. When he comes out of the mosque/ masjid, e‘tikaf is over.