mid-15c., "a bagged appendage to the front of the breeches; often conspicuous" [OED], from Old English codd "a bag, pouch, husk," in Middle English, "testicles" (common Germanic, cf. Old Norse koddi "pillow," Dutch kodde "bag") + piece (n.).
pouchlike addition to men's long hose, located at the crotch, worn first in the 15th century. It came into fashion with hose that were like tights and continued to be worn with breeches, or trousers. An earlier, narrower form of codpiece, worn with a belt or loincloth instead of hose or tights, was the basic fashion for men in the Aegean area during the Bronze Age.