Although it is not customary to wear Tefillin at night, Halacha follows the view that fundamentally, "Layla Zeman Tefillin" – Tefillin may be worn at night. As far as the essential Misva of Tefillin is concerned, it applies even at night. The reason why, as a practical matter, we do not wear Tefillin at night is because of the concern that one may fall asleep while wearing them, and it is forbidden to sleep with Tefillin because one cannot ensure proper bodily cleanliness while sleeping. Nevertheless, the Shulhan Aruch rules that if one was wearing Tefillin late in the afternoon, he does not have to remove his Tefillin before sundown, and he may continue wearing Tefillin into the night. Although one may not put Tefillin on at night, he may continue wearing Tefillin if he had been wearing them during the day, before sunset.
This Halacha was applicable in the olden days when people wore Tefillin the entire day, and is also relevant in our times on fast days, when, according to Sephardic practice, Tefillin are worn during Minha. According to the Shulhan Aruch, if one prays Minha in the late afternoon hours on a fast day, he does not have to ensure to remove his Tefillin before sundown, and may keep them on even after the sun sets.
The Kabbalists, however, following the view of the Arizal (Rav Yishak Luria of Safed, 1534-1572) in Sha’ar Ha’kavanot, maintain that the Tefillin must be removed before sundown, and may not be worn at night. Therefore, there are those who make a point of looking at the clock on a fast day to ensure that the Tefillin are removed before the sun sets. Hacham David Yosef writes that it is proper to follow the stringent ruling of the Kabbalists in this regard and remove one’s Tefillin before sundown.
Summary: According to Kabbalistic teaching, one who is wearing Tefillin in the late afternoon – as Sepharadim often do on fast days, when Tefillin are worn during Minha – must ensure to remove the Tefillin before sunset, and it is proper to follow this custom.