REMOVING TEFILIN [Tefilin :removing]
Gemara
(Rav Nachman): "Asher Herim Yad ba'Melech Shlomo" teaches that Yarav'am removed his Tefilin in front of Shlomo.
Menachos 36a (Beraisa): One puts on the Shel Yad before the Shel Rosh. When removing them, he removes the Shel Rosh before the Shel Yad.
(Rabah): He removes the Shel Rosh first due to "v'Hayu (plural) l'Totafos Bein Einecha" - whenever Tefilin are on your head, you are wearing both.
Rishonim
Rif and Rosh (Hilchos Tefilin (after Menachos) 8b and Siman 15): One removes the Shel Rosh before the Shel Yad.
Rambam (Hilchos Tefilin 4:8): When removing Tefilin, one should not put the Shel Rosh in the Kli on top of the Shel Yad, for then the next time he puts them on, he will encounter the Shel Rosh first. He will need to put it aside, for we put on the Shel Yad before the Shel Rosh. One may not leave aside a Mitzvah and go to do another Mitzvah. Rather, he must do the first Mitzvah that comes to him. Therefore, he puts the Shel Yad in the Keli last, on top of the Shel Rosh, so the next time he will encounter it first.
Rambam (Hilchos Talmud Torah 5:6): One may not remove Tefilin in front of his Rebbi.
Poskim
Shulchan Aruch (25:13): The universal custom is not to remove Tefilin before the Kedushah in u'Va l'Tziyon.
Magen Avraham (27): Some say not to leave Tefilin on more than necessarily, for they require a clean body (not to pass gas). Others disagree. It depends on the person.
Mishnah Berurah (55): If one fears lest he pass gas, he should remove them immediately. This is why nowadays most people do not wear Tefilin the entire day. The Ari Zal removed Tefilin after Al Ken Nekaveh. If there will be a Bris Milah, one should not remove Tefilin before it, for both of these are called 'Os' (a sign).
Kaf ha'Chayim (89): One should not remove Tefilin before learning at least a little. One merits Nefesh, Ru'ach and Neshamah only through learning with Tefilin on, especially of R. Tam!
Rema: Some say that according to Kabalah, one should not remove them until saying three Kedushos and four Kaddeshim, i.e. after mourner's Kaddish. Meticulous people do so.
Darchei Moshe (3): This is from Pesach Einayim. The letters 'Shin' on the Shel Rosh hint to this. One has three prongs, and the other has four.
Magen Avraham (28 and Gra 37): The correct text says three Kaddeshim and four Kedushos, i.e. Borchu (it is Davar shebi'Kedushah), and the Kedushos in Yotzer Ohr, Chazaras ha'Shatz and u'Va l'Tziyon.
Mishnah Berurah (56): Where the custom is to say mourner's Kaddish after Aleinu, one should not remove Tefilin before it. One should not remove or wrap Tefilin during Kaddish; he should be listening attentively.
Mishnah Berurah (58): If one must remove Tefilin before the Sefer Torah is returned, he should not remove the Shel Rosh in front of the Sefer Torah. Rather, he turns to the side. We are not concerned for the Shel Yad, or for the Shel Rosh if it is covered by his Talis.
Sha'arei Teshuvah (28:2): Ateres Zekenim (25:2) says that the Zohar praises leaving Tefilin on until leaving the Beis ha'Keneses. Shalmei Tzibur disputes this. Perhaps Ateres Zekenim holds that just like one should enter wearing Tefilin, the same applies to leaving. This is not necessarily true.
Shulchan Aruch (ibid.): On Rosh Chodesh, we remove Tefilin before Musaf.
Mishnah Berurah (59): Here, we remove Tefilin after the Kaddish before Musaf. Eliyahu Rabah says that one should remove it in u'Va l'Tziyon, when saying Yehi Ratzon... she'Nishmor Chukecha. In this way, he need not interrupt between Kaddish and Shemoneh Esre.
Shulchan Aruch (28:2): One removes the Shel Rosh first, due to "v'Hayu l'Totafos Bein Einecha."
Magen Avraham (2): One removes the Shel Rosh before removing the strap (of the Shel Yad) from his finger.
Eshel Avraham (2 and Be'er Heitev 2): Eliyahu Rabah cites Galya Razya, who says that one removes the Shel Rosh after removing the strap from his finger. This is the custom. Perhaps it is a printing mistake in the Magen Avraham. Some texts of the Magen Avraham say 'after'.
Machatzis ha'Shekel (27:12): We do not wrap the strap on the finger until after putting on the Shel Rosh, and we remove the strap from the finger before taking off the Shel Rosh.
Kaf ha'Chayim (5): Sefer ha'Kavanos says that we first remove the windings from the finger, and two or three windings from the arm, so it is as if we removed the Shel Yad, and then the Shel Rosh, and then the Shel Yad. This fulfills both opinions about which to remove first.
Sha'arei Teshuvah (25:19): The Talis should be on until removing Tefilin.
Shulchan Aruch (ibid): One removes the Shel Rosh while standing.
Source: Beis Yosef DH Kasuv, citing Ma'areches ha'Elokus.
Mishnah Berurah (6): Since we put on also the Shel Yad while standing, we remove also it while standing. Some Chachamim remove the head Tefilin with the left (weak) hand, to show reluctance to remove it.
Kaf ha'Chayim (7): We remove the Shel Yad while sitting. One may stand while unwinding the strap from the arm.
Shulchan Aruch (ibid): One puts the Shel Yad over the Shel Rosh in the bag, so the next time he puts on Tefilin, he will encounter the Shel Yad first.
Mishnah Berurah (7,8): The Bach and Taz say that the Tefilin bag should be long and narrow, so the Shel Rosh will be over the Shel Yad. The custom follows the Magen Avraham, who says that it is better that they be side by side. The Shel Rosh should be on the right, so one will encounter it first. One should not take off the Shel Yad until he puts away the Shel Rosh, lest he put the Shel Yad in the bag first.
Kaf ha'Chayim (14,15): One should be consistent to always put the Shel Rosh on the right, or always on the left, so it will be habit and he will never take it out first. The Shel Yad should not be on top of the Shel Rosh, for the Shel Rosh is more Kodesh. Similarly, a Talis or Sidur should not rest on top of Tefilin.
Shulchan Aruch (3): It is the custom of Chachamim to kiss Tefilin when putting them on and taking them off.
Source: Beis Yosef DH Kosav, citing the Avudraham and Orchos Chayim.
Mishnah Berurah (9): One may not wrap the straps on the boxes themselves, rather, on the sides. One holds the Tefilin and wraps the strap on it. He does not hold the strap and roll the Tefilin into it.
Dinim v'Hanhagos (Chazon Ish, 3:11): One must be careful that the straps not drag on the floor, also when donning or removing Tefilin.
Shulchan Aruch (38:11): One may not remove Tefilin in front of his Rebbi, due to fear of him.
Beis Yosef (DH Omar): Rashi explains that Yarav'am should not have removed his Tefilin in front of Shlomo, due to fear of the king. It is disgraceful to bare his head in front of the king. Mahari Avuhav says that Shimusha Raba learns from here that it is brazen to remove Tefilin in front of his Rebbi. However, why does he say 'before his Rebbi remove Tefilin'? Perhaps it is due to a different reasoning. It looks like casting off Hash-m's yoke, so one should not do so in front of his Rebbi until his Rebbi does so. Also, it is like teaching a law in front of his Rebbi, that now one is exempt from Tefilin. The latter reason applies only close to sunset. One should be stringent like Rashi.
Taz (4): According to Mahari Avuhav, if one removed Tefilin in front of his Rebbi, it helps to wrap them after his Rebbi, for as long as he does not wrap, it looks like he removed them just to go to the bathroom.
Magen Avraham (14): The Shlah says that removing Tefilin prevents the Talmid from serving his Rebbi. One may remove his Rebbi's shoes or take his clothes to the bathhouse only if the Talmid is wearing Tefilin, for then there is no concern lest people think that he is a slave.
Mishnah Berurah (35): The Isur applies to Rabo Muvhak, from whom he learned most of his Chachmah.
Mishnah Berurah (36): If it is almost sunset, it is a problem to remove Tefilin before his Rebbi even if he does not bare his head.