Hello, it’s known the halcha that one cannot say Davar shebekdusha without being clean or without being in a clean place or when needing the bathroom to a ceirtan amount of need,
Although it makes sense that this would be the case for tefillin as well whats the Torah source that one must follow the above guidelines for tefillin as well ואם תמצא לומר שזה מבואר בגמרא בשבת דף נט ״אָמַר רַבִּי יַנַּאי: תְּפִילִּין צְרִיכִין גּוּף נָקִי כֶּאֱלִישָׁע בַּעַל כְּנָפַיִם״
זה לא ראייה משום שהגמרא שם מסביר שם ״מַאי הִיא אַבָּיֵי אָמַר: שֶׁלֹּא יָפִיחַ בָּהֶן. רָבָא אָמַר: שֶׁלֹּא יִישַׁן בָּהֶם״
ולא שזה כמו והיה מחנך קדוש וכמו תפילה, שגוף נקי זה משהו אחר
The reason we can not say a davar shebkedusha in an unclean place is because when we think divrei Torah or daven, the shechina is with us, and the divine presence cannot be in an unclean place, and it is disrespectful to pull it to an unclean place. (See Orach Chaim 74, and Shulchan Aruch Horav 74-1). When a person wears tefillin, he is binding and tying Hashem holy name to his head and arm. Therefore, it is understandable, that those guidelines also apply to when one is in the presence of the shechina and is wearing his tefillin. This didea is also brought in sefer Chazon Yechezkel (Shabbos 49a [not 59]) who explains the reason why tefillin needs kuf naki, because when a person is wearing tefillin it is as if he is constantly learning, and a person learning needs to have a guf naki. According to this, we see that when one wears tefillin he needs more separation from unclean things then when he is learning, because when he is wearing tefillin he also has the idea of “shelo yafiach bahem”.