The core prohibition is set out by the Mishnah, which rules that wine used as an idolatrous libation is forbidden and forbids any mixture it touches even in the most minute quantity (Mishnah Avodah Zarah 5:8), and the Mishnah further details the mechanics of when grape juice in a winepress actually attains the status of wine so as to become susceptible to this prohibition once it descends into the collection vat (Mishnah Avodah Zarah 4:8-12). The Gemara in Avodah Zarah elaborates the scope of 'stam yeinam,' nondescript gentile wine, as forbidden for benefit and capable of conveying impurity as a liquid, while distinguishing the case of wine merely deposited with a gentile, which may be forbidden to drink but not to benefit from (Avodah Zarah 31a:1-3), and the Gemara also discusses how even a day-old gentile infant's touch can render wine forbidden for drinking though not necessarily for benefit, as seen in the incident at Biram (Avodah Zarah 57a-59b).
The Mishnah (Avodah Zarah 29b) catalogues gentile wine among the few items whose prohibition extends to benefit itself, not merely consumption (Avodah Zarah 29b:1), and the Gemara traces the decree against gentile wine, bread, and oil to the eighteen decrees of the students of Hillel and Shammai, linking it to concern about intermarriage (Avodah Zarah 36b:2-4).
The Rambam grounds the Biblical-level prohibition specifically in wine actually poured as a libation to a false deity, for which one is liable to lashes for even the smallest quantity, deriving this from the pasuk describing those who ate the fat and drank the wine of idolatrous offerings (Mishneh Torah, Forbidden Foods 11:1-25), and the Sefer HaChinukh explains that Chazal extended this, as a further distancing measure, to all nondescript gentile wine even absent certain knowledge of actual libation, terming it 'stam yeinam' (Sefer HaChinukh 111:3-5), and further records that Chazal extended the prohibition even to beer made from such wine and to wages earned for merely handling barrels of it, so as to uproot any desire for its continued existence (Sefer HaChinukh 111:7).
The Shulchan Arukh codifies the operative law: gentile wine is forbidden for benefit, and the Rema explains this stems from the decree enacted on account of ancient libation practices, though he notes that where such practice is no longer common some permit benefit from mere gentile contact with wine, restricting the prohibition to drinking alone (Shulchan Arukh, Yoreh De'ah 123:1). The Shulchan Arukh and Rema further detail who is capable of 'making' yayin nesech through contact, the conditions required for that contact to render wine forbidden even for benefit, and the particulars of a gentile infant's touch (Shulchan Arukh, Yoreh De'ah 124:1), as well as the laws of wine affected 'through the force of' a gentile's action, such as lifting or pouring a vessel (Shulchan Arukh, Yoreh De'ah 125:1-3), and the laws of absorption in vessels previously used for gentile wine (Shulchan Arukh, Yoreh De'ah 135:1). The Rema also records that one who unknowingly drank yayin nesech is advised by some to fast five days, corresponding to the five mentions of the vine in the Chumash, to achieve atonement (Shulchan Arukh, Yoreh De'ah 123:26).
The Levush elaborates the Shulchan Arukh's distinction regarding a gentile lifting or pouring a vessel of wine: where the wine flows through the gentile's deliberate action it becomes forbidden even absent direct touch, whereas wine released by mere tilting without lifting or touching remains permitted, since this is not the normal manner of libation (Levush, Yoreh De'ah 124:18). The Jerusalem Talmud similarly distinguishes types of wine by the degree of certainty of idolatrous use: wine actually witnessed being poured as a libation conveys severe impurity like a sheretz, while nondescript gentile wine is forbidden but does not convey that impurity (Jerusalem Talmud Avodah Zarah 2:3).
The Tosefta supplies leniencies for ordinary winepress labor shared between a Jew and a gentile, ruling that incidental contact with wine on the hands during such routine work does not render it forbidden, since that is not the normal manner of performing a libation (Tosefta Avodah Zarah 8:1-8).
The question of yayin nesech is rooted in the episode of Noach, the first to plant a vineyard, who became drunk from its wine (Bereishit 9:20-27), and the Torah elsewhere condemns the wine of the nations in harsh terms, likening it to the venom of serpents (Devarim 32:32-33).
Rav Tzvi Pesach Frank rules that although yayin nesech is treated like material associated with idolatry, wine that had already been nullified and rendered permitted before being cooked cannot retroactively be reclassified as yayin nesech (Har Tzvi YD 114).
The Chazon Ish addresses the mechanics of how wine becomes forbidden through a libation act, ruling that wine actually poured incurs the stringency of forbidden status while wine remaining in the vessel is not automatically forbidden, except where the person held the vessel while pouring, in which case the act is considered to apply to all the wine in the vessel, including through the vessel's lifting (Chazon Ish YD 40).
Rav Shmuel Wosner's Shevet HaLevi takes up practical evidentiary questions concerning yayin nesech, addressing how testimony establishing or denying that wine became forbidden is weighed, the significance of a litigant's silence, the distinction between testimony that permits versus testimony that forbids, and the status of containers used over time to store wine (Shevet HaLevi 2:54).
Rav Menashe Klein's Mishneh Halachos considers a contemporary case of whiskey aged in barrels that had previously held stam yeinam, initially leaning toward permitting it on the grounds that the absorbed wine is minimal and nullified, while raising concerns about deliberately nullifying prohibited wine and ultimately offering several grounds for leniency, and he further weighs whether one who unknowingly drank such whiskey must undertake a fast of atonement, contrasting positions calling for five or seventy-three fasts depending on whether the yayin nesech was consumed knowingly or by accident (Mishneh Halachos 10:108).