Sadly some dogs are punished in this scenario, when really it is often the owner that hasn't taken the time to complete the training for that behaviour and should be punishing them selves as bad owners!
When we teach a new behaviour we start in the most boring room of the house perhaps with no windows viewing the outside world and no fun toys lying around, when the dog knows the behaviour and is responding 9/10 times with enthusiasm, we must then teach the behaviour in the next environment which may be a slightly more distracting room or adding in small distraction to the current room.
Dogs learn under certain contexts, they don't necessarily understand that sit means sit everywhere, but rather sit means sit in the room that I learnt it.
In short in each new environment that we progress a skill we must go back to the teaching stage of it to ensure success, once the dog is obeying the command several times we can then make it slightly harder eg:
- When teaching the sit for the first time we might use a lure to show the dog what the sit position is, you will then progress to just a hand movement, when you take the behaviour outside for the first time, go back and use the lure for the first few repetitions or as many needed to ensure the dog understands that yes he must too 'sit' outside not just inside where he first learnt the command.