It not only sounds cruel, it IS cruel. This type of treatment has no place in a today's civilised society. The dog does not associate the treatment with what it has done, and if it is as a result of an infection, then you will end up with a dog that is frightened to do what it cannot help.
If the peeing is not due to any medical reason, then you need to try to ascertain what is making it do it. Perhaps the dog feels insecure in a new house. Did you have the dog from a baby puppy, or did you get it at an older age? Might is have been traumatised by being left on its own in a strange house as a youngster? There could be many reasons why it is doing this.