Aisha said, "I would enter the house for some need even when there was a sick person inside, and I would only inquire about him as I passed by. The Messenger of Allah ﷺ used to lean his head in to me while he was in the mosque, and I would comb his hair. He would not enter the house except for a necessity when he was in itikaf."
قالت: إن كنت لأدخل البيت للحاجة والمريض فيه، فما أسأل عنه إلا وأنا مارة وإن كان رسول الله ﷺ ليدخل علي رأسه وهو في المسجد فأرجله، وكان لا يدخل البيت إلا لحاجة إذا كان معتكفا.
Bukhari narrated it in the Book of Itikaf (2029), and Muslim in the Book of Menstruation (7:297), both through Layth, from Ibn Shihab, from Urwa bin Zubayr and Amra bint Abdul-Rahman, from Ayesha, and related it as mentioned.As for what was narrated from Ayesha, that she said, "The Prophet ﷺ would pass by a sick person while he was in itikaf, and he would just pass by as he was, not stopping to ask about him," this is daif. Abu Dawud narrated it (2464) from Muhammad bin Isa, who said, Abdul-Salam bin Harb told us, Layth bin Abu Salim informed us, from Abdul-Rahman bin Qasim, from his father, from Ayesha, who said (and related it as mentioned). Layth bin Abu Salim's hadith is confused, as Ahmad said, and Munziri, Ibn Hajar, and others faulted the hadith on this basis. They said, what is sahih from Ayesha is from her own practice, as Muslim narrated (297) from Urwa and Amra, from her, that Ayesha said, "I would enter the house for some need while a sick person was in it, and I would only ask about him while passing by."There is nothing in this indicating that she used to go out to visit the sick. Rather, she used to go out for some necessary need. This is confirmed by what Abdul-Razzaq narrated (8056) from Amra, from her, that she said, "She would pass by a sick person among her family while passing through, and would not turn aside for him." In another report from him, "Ayesha, while in her itikaf, when she went out to her house for some need, would pass by the sick person and ask about him while passing through, without stopping over him." And in Nasai's Kubra (3371), "When she was in itikaf, she would not ask about the sick person except while walking, without stopping."So the statement of Ibn Hajar and others, "what is sahih from Ayesha is from her own practice," gives the impression that she used to go out to visit the sick while in itikaf, whereas what is actually sahih is that she used to go out for some need and would pass by the sick person, asking about him while walking.On this subject there is also what was narrated from Anas bin Malik, as a raised report, "The one in itikaf follows the funeral procession and visits the sick," but this is fabricated. Ibn Majah narrated it (1777) from Ahmad bin Mansur, who said, Yunus bin Muhammad told us, who said, Hayyaj Khurasani told us, who said, Anbasah bin Abdul-Rahman told us, from Abdul-Khaliq, from Anas bin Malik, and related it as mentioned.Regarding Hayyaj Khurasani, Ahmad said, "His hadith is to be abandoned." Abu Dawud, Nasai, and others declared him daif. His teacher Anbasah bin Abdul-Rahman is even weaker than him. Abu Hatim Razi said of him, "He used to fabricate hadith." Al-Jarh wal-Tadil (6/403). Nasai said, "To be abandoned." His teacher Abdul-Khaliq is unknown, and no one narrated from him except Anbasah the liar. So in this chain there is a whole series of weak and abandoned narrators.What can be drawn from the hadiths on this subject is that one should not deliberately leave the masjid without a real need, since doing so defeats the very purpose of itikaf, which is devoting oneself fully to worship, prayer, remembrance, supplication, repentance, seeking forgiveness, reciting the Quran, and similar acts of obedience that bring one closer to Allah Almighty. It is permissible for the one in itikaf to leave the masjid for what is genuinely necessary, such as obtaining food and drink, relieving himself, performing wudu, washing after janaba, and going out for Friday prayer. It is likewise permissible for a relative to visit him, to check on his wellbeing, and to bring him what he needs of food, drink, clothing, medicine, or religious books, and to converse with him for a short while, and he himself may leave his place of itikaf to see such a person off.