Toddlers are small, and public toilets are not built for them. The seat is wide enough to fall through, the bowl is deep and loud, and their feet dangle, which makes the whole body feel unstable. Pooping needs the opposite: feet planted, body relaxed, a feeling of safety.
Then come the surprises. Automatic flushes trigger when a child wriggles, with a roar that happens right underneath them. Hand dryers start without warning. Doors bang. Strangers come and go. A child who has had one bad experience with an auto-flush often refuses every public toilet after that, because they cannot tell which ones will do it.
For a child who is already wary of pooping, this fear attaches to the toilet itself. They may start holding on outings, then holding more generally, then refusing the home toilet for poop. Catching the public-toilet fear early keeps it from spreading.
The good news is that this fear responds well to predictability. Children who know what will happen, and have the power to stop the scary part, usually relax quickly.