Yup, at four months dogs are still experiencing a lot of physical and mental/neurological changes as they develop, so it's not at all uncommon to see regression in potty training or a change in potty behavior. If it's extreme or the poop itself is concerning, of course consider calling a vet (eg explosive diarrhea, persistent sloppy stools, lots of straining with no or very little poop, blood, worms, etc), but if it's just a regular poop that caught them off-guard at an unexpected moment... happens to the best of us, lol. Or he might've gotten distracted by something when he was out and completely forgot to go - another frequent puppy problem.
Keep up reinforcing pottying outside with treats and praise. Don't punish accidents, and try to avoid even acting frustrated or upset when they happen - if you catch them in the act, rush them out and praise when they finish, then clean up the mess without fuss, and if you don't catch them, just take note of when it happened and clean it up. If you're anticipating a poop (or pee) and they don't go, either pop them into a crate/pen for 5-10 minutes and try again, or watch them like a hawk and try again in a few minutes (tethering them to you can help).
What helped me was actually physically writing down when accidents were happening, so I had a better idea of the circumstances where I had to be super vigilant with my puppy, and when he was probably fine to wander the apartment without my constant attention. For us things like weather mattered, because he wasn't as keen on pottying outside when it was really grossly wet and chilly, so we had more accidents on rainy days until we really got on him about frequent trips and keeping him in the pen if he hadn't emptied recently enough to be 'safe'.