V.W.
Could be constipation. My daughter (at 3 years old) went through a similar issue. It ONY happened at bedtime. And it wasn't a stalling tactic. She would go to sleep (and she was a champion sleeper and no issues going to bed either) and then she would wake up an hour later in pain.
Essentially, impaction would press on her bladder, causing bladder spasms and that is some intense pain. Some nights it was just uncomfortable and some nights she was literally SCREAMING in pain... not nonstop---in spasms. It took a while for her to be correctly diagnosed, because she WAS pooping. She evidently just was not fully emptying, and would stop when the urge was gone, but before she was really done. Eventually, it caused impaction.
The spasms were intermittent, too, so it was really hard to get it figured out. No rhyme or reason to them. She'd spasm one night, then be fine for weeks, then have a week where she spasmed a couple of random nights, then be fine for weeks again. And it ONLY happened at night, usually after she was already asleep.