I agree 100% with NOT punishing him by locking him in the bathroom.
If you don't catch the dog in the act and correct him at that time, correction at a later time (locking him in the bathroom) does nothing.
Otherwise he has no idea why he's being punished.

Something you might want to think about would be litter box training your dog. Here's a site to look at:
http://www.kturby.com/litter/litter.htm