Going out of the mosque is of three types:
1- A type that does not require setting out a condition (that is, when one intends to practise I‘tikaaf (seclusion in the mosque) he sets a condition that he would leave the mosque for certain purposes without having his I‘tikaaf interrupted). Scholars have regulated this type by a very simple rule saying that this includes what is necessary for man naturally and Sharee‘ah-wise, like eating, drinking, answering the call of nature, receiving medical treatment and the like of what one requires, even if it is not previously set out as a condition. The rule is what counts here and there may be other examples.
2- A type that is permissible and does not interrupt I‘tikaaf if one sets it out as a condition. However, if it is not set out as a condition and one goes out of the mosque, his I‘tikaaf will be interrupted and invalidated and he would need to start it again. The scholars’ rule in this regard is that it is in relation to every deed that brings one closer to Allah but is not obligatory. This includes, for instance, visiting the sick, following funerals, etc. According to the scholars’ preponderant opinion, if one sets out a condition to visit a specific patient or follow a funeral, it will be permissible for him to go out of the mosque, otherwise, it will be impermissible for him to do so and I‘tikaaf would be interrupted. An exception to this is the case of when one passes by one such thing on your way like ‘Aa’ishah, may Allah be pleased with her, would do. A person may wonder how one can set out a condition to attend the funeral of a specific person. To answer this we say that if he knows someone who is in the hospital and upon whom there are signs that indicate the possibility of his death, he may set out the condition of attending his funeral in case he dies. What is even easier is to say that one shall make I‘tikaaf and in case anyone, whose funeral he wishes to attend, dies, his I‘tikaaf will not be invalidated, without specifying anyone. If one does not set out such a condition, his I‘tikaaf will be interrupted and he has to return and restart it, in which case no blame will be on him unless it is an obligatory I‘tikaaf.
3- A type that invalidates I‘tikaaf, whether or not it is set up as a condition, like selling and buying, or going to work. This is impermissible, however, some scholars said that seeking knowledge is permissible.