The use of the figure of speech “to pull in one’s horns” with the meaning, “to retract, or to check oneself,” has been traced back to the fourteenth century.
The allusion is to the snail which, when its hornlike tentacles touch something strange, possibly perilous, immediately retracts one or both of them.