I've had this issue intermittently with both of my dogs. Neither one has a clear 'tell' to let me know they need to go to the bathroom, so it's very much on me to take them out regularly. Of course, it's hard to always keep track of who's been drinking more water, and occasionally there are mix ups in communication between my partner and myself about when they last went out, and sometimes you just have to go more frequently than normal, so accidents happen.
My guess is that it's a combination of things. Your dogs know when you aren't around they can't ask you go to out, so they hold it. But if you're home and they give you a signal, they may be thinking "oh well, I told her I had to go..." if you don't immediately respond. Access to water is potentially a big factor, as is confinement. If your dogs are kenneled or confined to a smaller space while you're away, they may be less likely to go close to where they have to rest.
Is the second dog new to your family? Start taking him out more often or start potty training over again...If the dog was 100% potty trained then something is upsetting the dog. I have a small dog and I take her out often and she has potty pads when I am at work if needed.