It is stated in Gittin (Gittin 45b): A Sefer Torah written by a min – shall be burned, for he certainly intended it for the sake of idolatry. If a star-worshiper wrote it – it shall be sequestered, for regarding him we do not say he wrote it for this sake, but rather because he is not included in the binding, as it is written: "And you shall bind them... and you shall write them" – anyone who is not included in binding is not included in writing. And so we learned in a Baraita: A Sefer Torah, tefillin, and mezuzot, which were written by a slave, a woman, a minor, a Kutite, an informer, an apostate, or a transgressor – are disqualified. For thus the Torah decreed, that anyone who is not included in the binding of tefillin, whether because they were not commanded, or because they cast off from themselves the yoke of the Kingdom of Heaven – they are not included in any writing. Therefore, regarding a mezuzah, even though women are obligated in mezuzah, nevertheless, since they are exempt from tefillin – they are disqualified from writing even that which they are obligated in. And whether they are permitted to sew the parchments in a Sefer Torah, we have explained with the help of Heaven in siman 278, see there. (And according to the Tosafot, an informer and a transgressor are only disqualified by rabbinic law.)
איתא בגיטין (גיטין מה ב): ספר תורה שכתבו מין – ישרף, דוודאי לשם עבודת כוכבים כיון. כתבו עובד כוכבים – יגנז, דביה לא אמרינן שכתבו לשם זה, אלא משום דאינו בקשירה, דכתיב: "וקשרתם וכו' וכתבתם" – כל שאינו בקשירה אינו בכתיבה. וכך שנינו בברייתא: ספר תורה תפילין ומזוזות, שכתבן עבד אשה וקטן, כותי, ומלשין, ומצרי, ועבריין – פסולים. דכך גזרה התורה, דכל שאינו בקשירת תפילין, או שלא נצטוו, או שפרקו מעליהם עול מלכות שמים – אינם בשום כתיבה. ולכן מזוזה, אף שנשים חייבות במזוזה, מכל מקום כיון דבתפילין פטורות – פסולות לכתיבה אפילו במה שחייבות. ואם מותרות בתפירת היריעות בספר תורה בארנו בסעייתא דשמיא בסימן רע"ח, עיין שם. (ולהתוספות מלשין ועבריין רק מדרבנן.)