expresses
the traditional belief that children need discipline and correction to develop good character. Historically the rod implied corporal punishment, which the saying should not be taken to endorse.
Imagine a case where you spoil children's character if you don't punish them when they are wrong.; then “Spare the rod and spoil the child” fits well.