The foundational prohibition is rooted in a Torah-level drashah, as the Beit Yosef (Even HaEzer 22) records that Rabbi Yochanan derived a biblical allusion to yichud from the pasuk 'כי יסיתך אחיך בן אמך,' with David HaMelech later extending the prohibition to seclusion with an unmarried Jewish woman, and Shammai and Hillel further extending it to a non-Jewish woman.
The Tur (Even HaEzer 22) rules that it is Biblically forbidden for a man to seclude himself with an ervah, and the Sages decreed against seclusion even with an unmarried woman or a non-Jewish woman, with the penalty of lashes for the violator.
The Rambam (Mishneh Torah, Forbidden Intercourse 22:1–12) rules that one woman may not enter into seclusion even with many men unless the wife of one of them is present, and similarly one man may not seclude himself even with many women, and that even a man whose profession brings him into regular contact with women is forbidden to seclude himself with them.
The Shulchan Arukh (Even HaEzer 22:5) codifies that one man may not be in seclusion even with many women, and in the Rama's gloss adds that at night — even in town — three men of fit character are required, unlike the two who suffice in town by day, indicating that nighttime conditions impose a heightened standard.
Sefer HaChinukh (375:4) states that this prohibition applies in every place and at every time, for both men and women, and that one who transgresses and becomes defiled in the ways described is liable to lashes.
The Gemara (Ketubot 13a) cites Rav's ruling that a man and woman are flogged for violating yichud as a rabbinic prohibition, though mere seclusion alone does not render a woman forbidden to her husband absent certainty of intercourse.
The Sulam on Zohar (Bereishit I 446) states explicitly that it is forbidden to seclude oneself with a woman privately unless her husband is with her.
The Gemara (Ketubot 13b) treats entry into a secluded or ruined space with a man as presumptively indicative of illicit relations, reflecting the principle that the concern of yichud is activated precisely by the absence of public visibility.