2,261. Yichud
Hilchos Issurei Biah 22:2
Jewish men are not suspected of intimacy with other men or animals so there is no prohibition against seclusion with them, though if one voluntarily distances himself from seclusion with them, it is praiseworthy. Great scholars would distance themselves from seclusion even with animals. The prohibition against seclusion with woman prohibited as forbidden relationships was transmitted as part of our oral tradition.
Hilchos Issurei Biah 22:3
After the incident of Amnon and Tamar (II Samuel 13), David and his court enacted a prohibition against secluding oneself with an unmarried woman. Even though an unmarried woman is not a prohibited relationship, doing so is considered tantamount to secluding oneself with a prohibited relation. Shammai and Hillel enacted a prohibition against secluding oneself with non-Jews. Therefore, if a man secludes himself with a woman – Jewish or non-Jewish – with whom seclusion is prohibited, both parties are given stripes for acting rebelliously and a public proclamation is made about them. The exception is a married woman; while it is prohibited to seclude oneself with her, stripes are not administered in order to prevent a rumor that she committed adultery, which could lead to another rumor that her children are illegitimate.