The word stag hasn't always meant "male deer". In Middle English, stag (from the Old English stacga) could mean the adult male of any animal, especially if castrated (!). In the 19th century it was even used to mean a turkey-c*ck of two years or older. Thus, a stag-night or stag-dinner was a function attended by males only.
Similarly, in Middle English, hen could mean the female of any bird. Thus a hen night or hen party is one which is exclusively female.
Unlike stag, which meant any male animal, the Old English henn meant a fowl of either sex.