The foundational concern underlying all these sources is the rabbinic decree against socializing with non-Jews in ways that could lead to intermarriage. The Rambam (Mishneh Torah, Forbidden Foods 17:9-17) states explicitly that Chazal forbade eating and drinking with non-Jews — even kosher wine and even from one's own utensils — specifically to prevent Jews from mingling with them and arriving at intermarriage, and he singles out drinking at a gentile's party (מסיבה) as categorically prohibited.
The Shulchan Arukh (Yoreh De'ah 114:1) builds on this foundation by distinguishing between incidental and established drinking in a non-Jew's premises: the core decree targets the concern that one will dine together (שמא יסעוד אצלו), and therefore the prohibition applies specifically when one makes a fixed, habitual place of drinking there — but entering a non-Jew's establishment and drinking in a temporary, incidental manner (דרך עראי באקראי) is permitted.
The Arukh HaShulchan (Yoreh De'ah 114:7) explains that the heart of the Rambam's rationale is that the prohibition targets drinking together in a shared social setting (מסיבה), not the mere act of consuming a beverage; it is the seated, communal gathering that the Sages sought to prevent, which is why bringing the drink home — away from that social context — was always allowed.
The Shelah, Shenei Luchot HaBerit (Shaar HaOtiyot, Kedushat HaAchilah 4:3), sharpens the practical line: drinking incidentally or while traveling at an inn is permitted, but establishing a fixed practice of drinking in a non-Jew's home is rabbinically forbidden on account of intermarriage concerns regardless of the drink; and while the Rema recorded the lenient custom of his communities on beer and grain-based beverages, the Shelah urges one to follow the stricter position.
A further dimension emerges from Avodah Zarah 8a, where a baraita in the name of Rabbi Yishmael warns that even Jews who attend a gentile's feast eating and drinking from their own kosher food and beverages — with their own attendant serving them — are considered by Scripture as though they partook of idolatrous offerings, because the very act of participating in the gathering carries consequences; the Gemara there traces the prohibition from the moment of the invitation itself.
The Gemara in Avodah Zarah 35b and Avodah Zarah 39b enumerate which foods and drinks of non-Jews are forbidden or permitted, and Avodah Zarah 38a delimits the prohibition of bishul akum, establishing that items not cooked — including beverages prepared without prohibited cooking — may have a different status; these sugyas form the textual substrate from which later authorities derive the rules about what one may drink even in a non-Jewish venue.
Taken together, these sources converge on a practical framework: what is critical is not the kashrut status of the beverage itself — a sealed kosher drink in a non-Jewish establishment raises no kashrut issue in itself — but rather whether one is establishing a fixed, social presence in the non-Jewish setting; incidental, temporary drinking is distinguished throughout the Shulchan Arukh (Yoreh De'ah 114:1) and the Shelah (Shaar HaOtiyot, Kedushat HaAchilah 4:3) from habitual attendance, and the concern of sitting and socializing as a regular matter recalls the very prohibition the Rambam (Mishneh Torah, Forbidden Foods 17:9-17) and Avodah Zarah 8a identify as the heart of the decree.