"frame of wood erected on a post or pole with holes into which were put the head and hands of an offender who was thus exposed for public derision and abuse," mid-14c., pillorie (attested in Anglo-Latin from late 12c., in surnames from mid-13c.), from Old French pilori "pillory" (mid-12c.), which is related to Medieval Latin pilloria, but all are of uncertain origin. Perhaps a diminutive of Latin pila "pillar, stone barrier" (see pillar), but OED finds this proposed derivation "phonologically unsuitable."
c. 1600, "punish by exposure in the pillory," from pillory (n.). Figurative sense of "expose publicly to ridicule, contempt, or abuse" is from 1690s. Related: Pilloried.