Sunan Abi Dawud Book 14, Hadith 162
Umar (may Allah be pleased with him) took a vow in the pre-Islamic days to spend a night or a day in devotion near the Ka'bah (in the sacred mosque). He asked the Prophet (ﷺ) about it. He said: Observe i'tikaf (i.e. spend a night or a day near the Ka'bah) and fast.
The sunnah for one who is observing i'tikaf (in a mosque) is not to visit a patient, or to attend a funeral, or touch or embrace one's wife, or go out for anything but necessary purposes. There is no i'tikaf without fasting, and there is no i'tikaf except in a congregational mosque.
The tradition mentioned above (No. 2468) has also been transmitted by Abdullah ibn Budayl through a different chain of narrators in a similar way.
This version adds: While he (Umar) was observing i'tikaf (in the sacred mosque), the people uttered (loudly): "Allah is most great." He said: What is this, Abdullah? He said: These are the captives of the Hawazin whom the Messenger of Allah (ﷺ) has set free. He said: This slave-girl too? He sent her along with them.