I`tikaf (devotional i`tikaf) means staying in the mosque to worship Allah, may He be exalted. End quote from Manar as-Sabil, 1/232.
Hence going out of the mosque invalidates i`tikaf, except in two situations:
- Going out for essential reasons, such as relieving himself if there are no facilities for that purpose in the mosque, or going out to bring food if there is no one who can bring it to him, and going out to pray Jumu`ah if there is no Jumu`ah in the mosque where he is observing i`tikaf.
- If he stipulated, when beginning his i`tikaf, that he would go out to do a righteous deed, such as visiting a sick person, or attending a funeral; or that he would go out for a permissible reason, such as to attend class, or to take a shower in his house, or to change his clothes, as mentioned in the question.
Al-Bahuti (may Allah have mercy on him) said in Ar-Rawd al-Murbi`, p. 245: The one who is observing i`tikaf should not go out of the place where he is observing his i`tikaf except for essential reasons, such as bringing food and drink because there is no one to bring them to him, or being overcome by the urge to vomit, urinate or defecate, or if he needs to do wudu’ or ghusl, or to go and wash something that he needs that got contaminated with impurity, and to attend Jumu`ah prayer or to give testimony if that is required of him. But the best is not to go early for Jumu`ah and not to stay too long afterwards...
And he should not visit a sick person or attend a funeral, as he is obliged to observe the i`tikaf without interruption, so long as he is not specifically required to do those things because there is no one else who can do it, unless he stipulated when starting his i`tikaf that he would go out to visit a sick person or attend a funeral. Similarly, he should not go out to do any righteous deed that he does not have to do and things that he can avoid, such as eating supper and staying overnight in his house. And he should not go out to engage in trade or earn income by doing handicrafts in the mosque, or go out to do whatever he wants. End quote.
It says in Matalib Uli an-Nuha, 2/242: When a person first vows to observe i`tikaf, he may stipulate that he may go out to do things that he does not have to do, such as attending Jumu`ah prayer, giving testimony, visiting the sick and attending a funeral; and any righteous deeds that he is not specifically required to do, such as visiting a friend, upholding ties of kinship, and washing a deceased person; or actions that he can do without and that are not acts of worship, such as stipulating that he can eat supper and stay overnight in his house, because observing the i`tikaf becomes obligatory once he forms the intention, like an endowment (waqf), and it becomes as if he vowed to devote the time that he spends there (in the mosque) as i`tikaf, and because there is a need to eat supper and stay overnight at home, and he cannot appoint someone else to do those things on his behalf. End quote.
It says in Kashshaf al-Qina`, 2/359: It is not valid for the one who wants to observe i`tikaf to stipulate that he may have intercourse with his wife, or stipulate that he may go out for fresh air or leisure, or to buy and sell and engage in trade, or to stipulate that he will earn income by doing some handicrafts in the mosque, or go out to do whatever he wants, because that is absolutely contrary to observing i`tikaf, like stipulating that he will not stay in the mosque, and like any endowment (waqf) in which it is not valid to stipulate a condition that contradicts or undermines it.
If he says: “If I get sick or some unforeseen circumstance arises, I will leave the mosque,” he may stipulate that condition, like stipulating a condition when entering ihram, because what it means is that it is permissible to exit ihram if something happens to prevent one from continuing. End quote.
Shaykh Ibn `Uthaymin (may Allah have mercy on him) said in his Ash-Sharh al-Mumti`, 6/523: From the words “unless he stipulates” we learn that it is permissible to stipulate that before starting to observe i`tikaf. Hence when he intends to begin his i`tikaf, he may say: I intend to observe i`tikaf except, O Lord, if I go out to visit a sick person or attend a funeral.
But this is not appropriate, and it is better to maintain the i`tikaf (and not interrupt it), unless the sick or dying person has a right over him, in which case stipulating this condition is better, meaning that the sick person is one of his relatives regarding whom not visiting them when they are sick may be regarded as severing ties of kinship. In that case, he should make this stipulation. And the same applies to attending a funeral. End quote.
To sum up: it is permissible for you to stipulate, before starting your i`tikaf, that you will go out for the purposes mentioned, namely attending classes, taking a shower and changing your clothes, but you must return to the mosque as soon as you have finished doing what you stipulated. If you delay, even for a short while, your i`tikaf will be invalidated and you will not be regarded as being in a state of i`tikaf because of this delay with no excuse.
It says in Sharh Muntaha al-Iradat, 1/505: The one who is observing an obligatory i`tikaf, if he goes out for a valid reason, must return as soon as that reason no longer applies, because the ruling is connected to its reason. Therefore if he delays his return and does not return as soon as it becomes possible for him to do so, even if it is only a short delay, it is similar to his going out for something that he could avoid, and in that case, his entire i`tikaf is rendered invalid.
But if you can take your clothes with you and change in the mosque, that is better and is closer to the Sunnah of i`tikaf.
Similarly, if you can delay attending your classes until after your i`tikaf, without that affecting your studies, or you can listen to a recording of the class, that will be better.
But if that cannot be done without affecting your studies, then you can stipulate that you will go out for essential purposes before starting your i`tikaf, and there will be nothing wrong with you doing that, in sha Allah.
And Allah knows best.