or suppose he doesn't understand why to not stray very far and this makes a mistake about it's importance. then it's first ignorance, second pain.
or suppose he doesn't understand what situations "don't stray very far from me" applies in and which it doesn't. then again, not knowing what his parent wants is followed by pain.
there is no lesson or learning there. what's going on is a lack of communication followed by pain. there isn't even punishing disobedience, because disobedience didn't take place. that's one sort of way spanking can be completely senseless.
now, suppose there was disobedience. is "disobey and i'll hurt you" really the best way to handle that? that's leadership by fear, not leadership by inspiration. you call this "a reason to listen" but it isn't, it's a reason to look for ways to avoid being hurt, whether they are what the parent wants, or not.