When the incident of Amnon and Tamar occurred, David and his beit din decreed the prohibition of yichud with an unmarried woman, even if she is a minor who does not yet have a menstrual cycle—for if she has a cycle, she is an ervah due to her niddah status as I have written—for even though she is not an ervah, she is included in the yichud of arayot. It is not that prior to this absolute yichud was permitted, for it is impossible to say so, and it is obvious that this is close to coming to transgression, for even in dances they are forbidden to dance together as it is written: "Young men and also maidens, elders with youths" (Psalms 148:12), and it is not written "young men with maidens"—conclude from this that for a young man and maiden to go together in dance is an absolute prohibition. And so too at the end of Judges (21:20-21) it is written: "And they commanded the children of Benjamin, saying: Go and lie in wait in the vineyards. And see, and behold, if the daughters of Shiloh come out to dance in the dances, then come out of the vineyards and snatch," etc. And why did they not command them to go into the dances? Rather, certainly this is an absolute prohibition and they would not have allowed the daughters of Shiloh to mingle with them; therefore, they commanded them to hide in the vineyards. Rather, they decreed even regarding temporary yichud as with arayot, and this is what the Rambam, the Tur, and the Shulchan Aruch wrote, that she is included in the yichud of arayot, meaning that even temporary yichud is forbidden. And as for Ruth secluding herself with Boaz—it was because she wanted him to marry her, as it turned out for her [see Yevamot 47b, and see Rashi there]. And Shammai and Hillel decreed regarding yichud with a gentile woman even regarding temporary yichud as with arayot. It follows that anyone who secludes himself with a woman with whom it is forbidden to have yichud, whether she is an Israelite or not an Israelite—they strike both of them with makat mardut, the man and the woman, and they make a public announcement about them in order to shame them. Nevertheless, they do not forbid the woman to the priesthood even if she secluded herself with one who would disqualify her from the priesthood through his cohabitation [Tur], except for a married woman, for even though she secluded herself they do not lash her so as not to bring out a bad report regarding her children, that they might say he cohabited with her; and if she sinned, what did her children sin, for this is only a concern regarding cohabitation. And some say that they lash him [Bach], and some say that they do not lash him either [Beit Shmuel], for when they lash him, a bad report will go out regarding her children that they are mamzerim. And that which was written in siman 21, section 3, that when one passes by the door of a suspected woman they lash him—this refers to an unmarried woman.
כשאירע מעשה אמנון ותמר גזר דוד ובית דינו על איסור יחוד עם פנויה אף שהיא קטנה שאין לה וסת עדיין, דביש לה וסת הרי היא ערוה מפני נדתה כמ"ש, דאע"פ שאינה ערוה – בכלל יחוד עריות היא. ולאו דקודם לזה היה מותר יחוד גמור, דא"א לומר כן ופשיטא שזהו קרוב לבא לידי עבירה, דאפילו במחולות אסורים לחול יחד כדכתיב "בַּחוּרִים וְגַם בְּתוּלוֹת זְקֵנִים עִם נְעָרִים" (תהלים קמח יב), ולא כתיב בחורים עם בתולות – ש"מ דלילך יחד במחול בחור ובתולה איסור גמור הוא, וכן בסוף שופטים (כא, כ– כא) כתיב "וַיְצַווּ אֶת בְּנֵי בִנְיָמִן לֵאמֹר לְכוּ וַאֲרַבְתֶּם בַּכְּרָמִים. וּרְאִיתֶם וְהִנֵּה אִם יֵצְאוּ בְנוֹת שִׁילוֹ לָחוּל בַּמְּחֹלוֹת וִיצָאתֶם מִן הַכְּרָמִים וַחֲטַפְתֶּם" וגו', ולמה לא צוו אותם שילכו בהמחולות? אלא ודאי דזהו איסור גמור הוא ולא היו מניחין בנות שילו שיתערבו עמהן, לכך צוום להסתר בכרמים. אלא שגזרו אף על יחוד ארעי כמו בעריות, וזהו שכתבו הרמב"ם והטור והשו"ע דבכלל יחוד עריות היא, כלומר דאפילו יחוד ארעי אסור. ומה שנתייחדה רות עם בעז – לפי שהיתה רוצה שישאנה, כמו שעלה לה [ע' יבמות מ"ז:, וע' רש"י שם]. ושמאי והלל גזרו על יחוד כותית אף על יחוד ארעי כמו בעריות, ונמצא שכל המתייחד עם אשה שאסור להתייחד עמה, בין ישראלית ובין אינה ישראלית – מכין את שניהם מכת מרדות האיש והאשה ומכריזין עליהם כדי לביישן, ומ"מ אין אוסרין את האשה לכהונה אפילו נתייחדה עם מי שפוסלה בביאתו לכהונה [טור], חוץ מאשת איש שאע"פ שנתייחדה אין לוקין אותה שלא להוציא לעז על בניה שיאמרו שבא עליה, ואם היא חטאה בניה מה חטאו דאין זה רק חשש על הביאה, וי"א דאותו מלקין [ב"ח], וי"א דגם אותו אין מלקין [ב"ש] דכשילקוהו יצא לעז על בניה שהם ממזרים, ומ"ש בסי' כ"א סעי' ג' דכשעובר על פתח החשודה מלקין אותו – מיירי בפנויה.