Maybe you did not read the signs properly when he was indicating that he had to go out, maybe the dog does not yet fully understand what housebreaking is, perhaps you forced him to wait too long and he was no longer able to hold it. Regardless, punishment has no place in housebreaking. What happens when they are doing something dictates whether they will ever perform that behavior again. Housebreaking will be hindered because when you take him outside to do his business, he will be afraid to perform in front of you. You'll bring him inside, he'll go off to a corner to eliminate, you'll catch him, punish him, and the cycle will repeat.
Dogs are naturally clean animals.
They are also habitual. Once you set up proper housebreaking protocol and they come to understand what is expected of them, they will gladly oblige. During the housebreaking stage, plan on spending a lot of time with your dog. Constant supervision is necessary unless the dog is crated. Puppies need to be taken out constantly, as often as every 90 minutes in very young dogs.