c. 1600, from Latin castigatus, past participle of castigare "to correct, set right; purify; chastise, punish," from castus "pure" (see caste) + agere "to do" (see act (n.)). The notion behind the word is "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)]