Dogs associate punishment with what they're doing at the time they're punished.
Punishing your dog after the fact won't eliminate the escaping behavior, but will probably make them afraid to come to you.
You must also give your dog less reason to escape and make it more difficult for them to do so.