Around this age children start to feel the urge to poop as a distinct sensation, and they discover they can do something about it: squeeze. For a toddler who is working out what is 'me' and 'mine', poop is one of the few things entirely under their control, and holding it can feel powerful.
At the same time, diets change, routines change, and many families start thinking about potty training. Any of these can lead to a harder poop. If that poop hurts, the lesson a two-year-old takes away is simple: pooping hurts, so don't. The next poop waits longer, dries out, and hurts more, which confirms the fear.
This is also the age when parents notice hiding, standing in a corner, or asking for a diaper. Those are not steps backwards. They are a child looking for the place and position where pooping feels safest.
The good news is that at two, habits are young. Lowering pressure and keeping poop soft usually unwinds holding before it becomes long-standing, which is why it is worth acting calmly now rather than waiting it out.