Punishment stops a behavior in the moment. A consequence, done well, teaches a child something they carry into the next decision. The two are often confused, but they aim at different targets.
A useful test
Ask whether the response is logically connected to what happened. A natural or logical consequence teaches cause and effect; an arbitrary punishment mostly teaches a child to avoid getting caught.