"So that the LORD's Torah may be in your mouth" (Exodus 13:9). Why is this said? Because Scripture says, "And it shall be for a sign upon your hand" (Exodus 13:9), I might understand that women and small children are included. And there is reason to argue so: since the mezuzah is a positive commandment and tefillin is a positive commandment, if you have learned about the mezuzah that it applies to women as to men, perhaps tefillin too applies to women as to men. Therefore Scripture teaches, "So that the LORD's Torah may be in your mouth" [the verse limits the obligation]; I have spoken only of one who is obligated in the study of Torah. From here they said: all are obligated in tefillin (another version: in Torah study) except women and slaves. Michal daughter of Saul used to lay tefillin; the wife of Jonah used to go up for the festival pilgrimage; Tabi the slave of Rabban Gamliel used to lay tefillin. "And for a remembrance between your eyes, so that the LORD's Torah may be in your mouth" (Exodus 13:9). From here they said: whoever lays tefillin is as one who reads in the Torah, and whoever reads in the Torah is exempt from tefillin. A Torah scroll sewn with flax thread: Rabbi Yehudah and Rabbi Meir [disagreed]. One said it is invalid, for it is written, "So that the LORD's Torah may be in your mouth" [comparing] all the Torah to tefillin: just as tefillin, by a law given to Moses at Sinai, must be sewn with sinews, so all the Torah must be sewn with sinews. And one said it is valid: the comparison is only to "that which is permitted in your mouth" [the parchment of clean animals], but it was not compared regarding its [other] laws.
Who Is Obligated in Tefillin and the Mark of Torah in the Mouth
Yalkut Shimoni on Torah 222:2
לְמַעַן תִּהְיֶה תּוֹרַת ה' בְּפִיךָ. לָמָּה נֶאֱמַר, לְפִי שֶׁהוּא אוֹמֵר וְהָיָה לְךָ לְאוֹת עַל יָדְךָ שׁוֹמֵעַ אֲנִי אַף הַנָּשִׁים וְהַטַּף בְּמַשְׁמָע, וְהַדִּין נוֹתֵן, הוֹאִיל וּמְזוּזָה מִצְוַת עֲשֵׂה וּתְפִלִּין מִצְוַת עֲשֵׂה, אִם לָמַדְתָּ עַל מְזוּזָה שֶׁהִיא נוֹהֶגֶת בְּנָשִׁים כְּבַאֲנָשִׁים יָכוֹל אַף תְּפִלִּין יִנְהֲגוּ בְּנָשִׁים כְּבַאֲנָשִׁים, תַּלְמוּד לוֹמַר, לְמַעַן תִּהְיֶה תּוֹרַת ה' בְּפִיךָ, לֹא אָמַרְתִּי אֶלָּא בְּמִי שֶׁהוּא חַיָּב בְּתַלְמוּד תּוֹרָה, מִכָּאן אָמְרוּ הַכֹּל חַיָּבִין בִּתְפִלִּין (נָ"א בת"ת) חוּץ מִנָּשִׁים וַעֲבָדִים. מִיכַל בַּת שָׁאוּל הָיְתָה מָנַחַת תְּפִלִּין, אִשְׁתּוֹ שֶׁל יוֹנָה הָיְתָה עוֹלָה לָרֶגֶל. טָבִי עַבְדּוֹ שֶׁל רַבָּן גַּמְלִיאֵל הָיָה מֵנִיח תְּפִלִּין. וּלְזִכָּרוֹן בֵּין עֵינֶיךָ לְמַעַן תִּהְיֶה תּוֹרַת ה' בְּפִיךָ. מִכָּאן אָמְרוּ, כָּל הַמֵּנִיח תְּפִלִּין כְּאִלּו קָרָא בַּתּוֹרָה וְכָל הַקּוֹרֵא בַּתּוֹרָה פָּטוּר מִתְּפִלִּין. סֵפֶר שֶׁתְּפָרוֹ בְּפִשְׁתָּן רַבִּי יְהוּדָה וְרַבִּי מֵאִיר חָד אָמַר פָּסוּל, דִּכְתִיב לְמַעַן תִּהְיֶה תּוֹרַת ה' בְּפִיךָ, אִיתְקַשׁ כָּל הַתּוֹרָה לִתְפִלִּין, מַה תְּפִלִּין הֲלָכָה לְמֹשֶׁה מִסִּינַי לְתָפְרָן בְּגִידִין, אַף כָּל הַתּוֹרָה לְתָפְרָהּ בְּגִידִין, וְחָד אָמַר כָּשֵׁר, כִּי אִיתְקַשׁ לַמּוּתָּר בְּפִיךָ, לְהִלְכוֹתָיו לֹא אִיתְקַשׁ.