Ewstephy is right. Don’t scold him for going inside. He will just wait until you leave the room or are gone to do it.
Sometimes my pit won’t potty if she knows I’m leaving because she knows I’ll stay longer waiting on her. I play fetch with her. Once she gets running around she can’t help it, she has to go.
I had a pit mix that had the same problem as your dog. I ended up crating him while I was gone or there’d be a mess every time. Maybe crate him while you sleep? Take him to potty just before bed then crate him then take him out first thing in the morning. My pit mix had separation anxiety when I left the house. That’s why he’d have accidents. He’d get so nervous in my absence he’d have to go potty.
Also I would take your dog to the vet and have him checked out. It is possible that there is a problem with him internally. It’s always nice to rule that out.