1607, from L. castigatus pp. of castigare "to purify, chastise," from castus "pure" (see caste) + agere "to do." Sense of "make someone pure by correcting or reproving him."
"If thou didst put this soure cold habit on To castigate thy pride, 'twere well." [Shakespeare, "Timon" IV.iii (1607)]