Old Dog

I know my dog is old and I guess confused, but every time he whines, and we open the door to let him outside, he walks away and ends up peeing and/or pooping in the house. I don’t understand and it’s frustrating. He’s 13, so maybe it’s dog dementia?