Dogs that do this feel they have two bathrooms, one inside and one outside. Somewhere along the way, you allowed this dog the freedom to roam and have accidents in your house that you did not (and probably still do not) catch in the act. For a dog that has gone to the bathroom many times in a certain area without anyone telling them not to (at the split second they are doing it), then in their mind….there is nothing wrong with going to the bathroom in the dining room. So when you go outside, they are more than likely focusing on other things like sniffing, playing, running, etc., and when they get back inside and you turn them loose again, they calm back down and remember that they need to use the bathroom, so they calmly walk into the other room to their indoor bathroom and go.