We have had our 2.5 year old potty trained for at least 6 months. He knows when he has to go and asks accordingly. At night he stays dry.
However, when he is at home and he is in trouble (or gets really upset) he frequently ends up peeing his pants. This last time I saw him run into the laundry room, stand in the corner and pee himself.
My wife and I have told him repeatedly that he needs to use the potty. This last time, my wife spanked his butt for doing this as he told me he did it on purpose. Other than these circumstances, he never has any issues going to the bathroom on time.
Are there any ways to discourage this behavior or is this just one of those phases that kids go though?