I use something similar when my 10 year old gets mad and "runs away."
I lock the door. I make him apologize before I let him back in. It can take a while. This has happened twice. I think he gets that it will keep happening until he changes his behavior. He hasn't tried it since.