The Tur wrote: But if he found in her a matter of immorality or licentiousness, it is a mitzvah to divorce her, as it is written, "Drive out the scorner, and contention will depart." Thus far his words. And the sages, of blessed memory, applied this verse to a bad wife, as has been written. But regarding immorality or licentiousness, it is a mitzvah from the Torah, as has been written (Beit Yosef). Also, the wording of the Shulchan Aruch in section 4 is slightly imprecise, as he equates the law of a bad wife to one who is not modest; yet in the Shas it is proven that regarding one who is not modest, there is a positive commandment from the Torah to divorce her. Also, the wording of the Rambam is difficult in this matter, as he also wrote in chapter 10, law 22: A wife who is bad in her temperaments and who is not modest like the fit daughters of Israel, it is a mitzvah to divorce her, as it is said, "Drive out the scorner, and contention will depart." Thus far his words. And he did not write that it is a mitzvah from the Torah to divorce her. And it must be said that he holds that this which the sages, of blessed memory, said—that it is a mitzvah from the Torah to divorce her—is only according to Beit Shammai; for according to Beit Hillel, it is not specifically a matter of immorality, for even if she burned his food (Lechem Mishneh). And one should not ask: how is it possible to say that according to Beit Hillel there is no mitzvah from the Torah to divorce her for a matter of immorality, when it is forbidden to be with her? For it can be said that although it is forbidden to be with her, nevertheless he is not obligated from the Torah to divorce her, but rather he shall distance her from him and take another. And so it is explained from the words of the Rambam at the beginning of the Laws of Divorce, that from the Torah, divorce is not a mitzvah at all, even in a case where she is forbidden to him, for he wrote that there is a positive commandment that the one who divorces shall divorce with a scroll. Thus far his words. And so he wrote in the Sefer HaMitzvot, mitzvah 222, and this is his wording: That He commanded us to divorce with a document in any event when we desire to divorce, and that is His, may He be blessed, statement, "and he shall write for her," etc. Thus far his words. It is clear from his words that to divorce is never a mitzvah, and the mitzvah is when we desire to divorce, not to divorce except with a document; and this is like the mitzvah of shechitah, that when we desire to eat meat, it is a mitzvah to slaughter. But from the words of the Rashba that we brought in section 5, it is explained that there is a mitzvah to divorce one who is fit to be divorced. And so it is explained from the Tosafot at the end of Gittin, who wrote that even according to Beit Hillel it is a mitzvah from the Torah to divorce a licentious woman; see there.
והטור כתב אבל אם מצא בה ערות דבר או פריצות מצוה לגרשה דכתיב גרש לץ ויצא מדון עכ"ל ופסוק זה אמרו חז"ל על אשה רעה וכמ"ש אבל בערוה או פריצות מצוה מן התורה כמ"ש (ב"י) וגם לשון הש"ע בסעי' ד' אינו מדוקדק קצת שמשוה דין אשה רעה לאינה צנועה ובש"ס מוכח דאינה צנועה יש מצות עשה מן התורה לגרשה וגם לשון הרמב"ם תמוה בזה שכתב ג"כ בפ"י דין כ"ב אשה רעה בדיעותיה ושאינה צנועה כבנות ישראל הכשירות מצוה לגרשה שנאמר גרש לץ ויצא מדון עכ"ל ולא כתב שמן התורה מצוה לגרשה וצ"ל דס"ל דזה שאמרו חז"ל דמן התורה מצוה לגרשה אינו אלא לב"ש דאלו לב"ה הלא לאו דווקא ערוה דאפילו הקדיחה תבשילו (לח"מ) ואין לשאול ואיך אפשר לומר דלב"ה אין מצוה מן התורה לגרשה בערות דבר והרי אסור להיות עמה די"ל דנהי דאסור להיות עמה מ"מ אינו מחוייב מן התורה לגרשה אלא ירחיקה ממנו ויקח אחרת וכן מתבאר מדברי הרמב"ם ריש הל' גירושין דמן התורה אין הגירושין מצוה כלל אפילו במקום שאסורה עליו שהרי כתב שיש מצות עשה שיגרש המגרש בספר עכ"ל וכ"כ בס' המצות מצוה רכ"ב וז"ל שצונו לגרש בשטר על כל פנים כשנתרצה לגרש והוא אמרו ית' וכתב לה וכו' עכ"ל מבואר מדבריו דלגרש אין מצוה לעולם והמצוה היא כשנרצה לגרש לבלי לגרש רק בשטר וזהו כמצות שחיטה שכשנרצה לאכול בשר מצוה לשחוט אבל מדברי הרשב"א שהבאנו בסעי' ה' מתבאר שיש מצוה לגרש מי שראויה להתגרש וכן מבואר מתוס' סוף גיטין שכתבו דגם לב"ה מצוה מן התורה לגרש פרוצה ע"ש: