The ettin has been present in the game since Hack for PDP-11, a variant of Jay Fenlason's Hack - from this version to the publicly distributed versions of Hack edited by Andries Brouwer, they used the e glyph. Their undead forms were introduced in NetHack 3.0.0.
A commented-out interaction is present in the code that would give YAFM when using the #chat extended command and selecting yourself while in the form of an ettin ("You discover that your other head makes boring conversation."); the rationale was that it would raise all sorts of questions about ettins being able to wear multiple helms or amulets, as well as similar queries about multi-limbed monsters such as the marilith.
The word "ettin" is an archaic English word, derived from the Old English Eoten and cognate to the Germanic/Old Norse Jötunn. Each of these words has been used to mean "giant" in some fashion. Their portrayal as two-headed and giant-like may be derived from J. R. R. Tolkien: the Ettenmoors are a region in Middle Earth inhabited by trolls, and Tolkien's Guide to the Names in The Lord of the Rings states the root to be the word eten which means “troll" or "ogre”; the second chapter of The Hobbit also has a character comment on trolls as being slovenly and lacking table manners, "even those with only one head each", implying that trolls are normally two-headed.
The ettins from the first Monster Manual of Dungeons & Dragons - and by proxy many portrayals of the ettin in later media - are likely based on this information. The first Manual depicts them as nocturnal two-headed giants that dwell in remote places and live underground, and establishes the ettin's advantages against stealthy foes that are used in later editions. NetHack borrows these elements, as well as their hit die (2-16 using the left arm and 3-18 using the right), though D&D ettins in this edition are chaotic rather than neutral.
The two-headed giant, or ettin, is a vicious and unpredictable hunter that stalks by night and eats any meat it can catch.