pen (n.3)
slang, "prison," 1884, shortening of penitentiary; earlier use (1845) probably is a figurative extension of pen (n.2).
pen (n.1)
"writing implement," late 13c., from Old French pene "quill pen; feather" (12c.) and directly from Latin penna "a feather, plume," in plural "a wing," in Late Latin, "a pen for writing," from Old Latin petna, pesna, from PIE *pet-na-, suffixed form of root *pet- "to rush; to fly" (see petition (n.)).

Latin penna and pinna "a feather, plume;" in plural "a wing;" also "a pinnacle; battlement" (see pin (n.)) are treated as identical in Watkins, etc., but regarded as separate (but confused) Latin words by Tucker and others, who derive pinna from PIE *spei- "sharp point" (see spike (n.1)) and see the "feather/wing" sense as secondary.

In later French, this word means only "long feather of a bird," while the equivalent of English plume is used for "writing implement," the senses of the two words thus are reversed from the situation in English. Pen-and-ink (adj.) is attested from 1670s. Pen name is recorded from mid-19c.
pen (v.2)
"to enclose in a pen," c.1200, from Old English *pennian, from the source of pen (n.2). Related: Penned; penning.
pen (n.2)
"enclosure for animals," Old English penn, penne, "enclosure, pen, fold," of uncertain origin, perhaps related to Old English pinn "pin, peg" (see pin (n.)) on notion of a bolted gate or else "structure made of pointed stakes."
pen (v.1)
late 15c., from pen (n.). Related: Penned; penning.