It sounds like he does know what to do but maybe can't hold it b/c of the Miralax. I don't think getting angry with him will help and I agree to NOT put him back in pull ups...you are right, that would be very confusing, and I'm betting he's already confused enough with the changes going on with his body. I recommend carefully considering anger and punishments by thinking of how they would make you respond - would someone being angry with you or taking things away make you want to do better? Most likely not. Would you do it anyway because of fear? Maybe. But do you really want your child to make decisions out of fear? Probably not.
I know you're frustrated, and believe me, I know how that is - at your wits end with nothing left in your tool kit...we've all been there, so please know that you are not alone. Just remember that all children usually experience some potty training setbacks - and this sounds like one for sure. It's usually a stressful life adjustment that causes them (ask yourself if there have been any new stressors in the family). Something like this can do it too - especially if it is stressing you - and then that becomes a stressor for him and it ends up being counterproductive to stress about it at all. Distractions can cause children to not pay attention to their body's signals, but in this case, it sounds like his body's signals have changed due to the medication (it comes on much faster than before most likely) and this might be confusing to him. Imagine how confused and discouraged he might feel about losing control of his body...especially after he thought he had the potty thing down and was probably feeling really good about it. I know parents face anger and disappointment when setbacks happen as well, but before you started to get angry and impose punishments, did you notice how he seemed to feel about having an accident? Does he understand that the medicine you have given him is the cause of the change in his body (but that he needs to take it for his best health, which seems to be how you feel)? Anger and punishment for having an accident is, most likely, counterproductive.
So what can you do instead you're probably asking?
1. Diet. Is it possible to make dietary changes that can eliminate the need for the Miralax? Serve high fiber foods or juice (peach or apricot nectar are high in fiber, so if you have to go to a juice to accomplish this, these might be good choices). Kiwi is another good one that should get his natural bowel movements back on track quickly. Go to fewer dairy products and apple juice, which tend to be constipating. But remember not to force any new foods (creates a power struggle) - just make them available and offer them. If he won't take them, you will still have to use the Mirilax, so if he knows the Mirilax is causing the problem, he might be more likely to try a new food or drink if he knows they will help instead. You don't want to create the same problem with the food though - this might cause him to be scared of eating it or ever trying new things - so you have to be careful here. Make sure he knows it will help, but not just like the meds - they will help better than the meds, then just be sure to not give too much so as to cause more accidents - this might take some trial and error, so just be sure he knows that too...start slow and keep increasing until it's the right amount for him. Once this really helps, he will know you guys did it (celebrate the team effort!!) and he will feel empowered because he chose to eat the foods - he will feel great about his decisions and empowered to make more!
2. Stress. Some parents (I am not saying you, but I wanted to mention this, just in case) push children to master too many tasks at once or expect perfection, which cause them to feel overwhelmed and stressed. Of course, they believe they are doing what is right by their children (most parents like this worry that setting limits will be too restrictive to a child's spirit). They often put many decisions on children ("Where should we eat today?", "Do you think mommy and daddy should go out tonight?", "Do you want to go to school today?"), but even if a child shows interest in such tasks or decisions early on (like potty training), forcing it takes an emotional toll.
3. Control. Control issues can also manifest in the form of toilet training problems. Avoid power struggles and instead, empower your child in positive ways (just like with the food I mentioned above). Encourage cooperation just as you would with any other challenge. Remember that problems are ALWAYS opportunities to learn. Feel free to apologize to him (without guilt or tears) for the anger and punishment you have put forth so far - explain to him that you weren't sure how to help him but that you guys are going to face this as a team and you believe in him and know he can do it - mean it. Say this without expectations of perfection so he does not feel pressured. Show empathy for him (without coddling or babying - no boo hooing, just matter of fact). Remember that logic will not resolve this one - it ends up being an illogical power struggle; the more determined you are to make him to do it, most likely he is becoming more determined not to.
4. Environment. Be sure the environment is potty friendly for him and make sure he is wearing clothing that is easy to get off. Especially with this new challenge of getting there in time (even more than normal)!
5. Time. Be patient, just as you probably were when the potty training started originally, and know that time works wonders. He will figure it out when he's ready - and I know he was already doing it, but this is a change in his body he is adjusting to. Be careful though, not to make it seem okay that he had an accident...you don't want him to feel like it's acceptable, but at the same time, you don't want to make him feel badly for it. It is what it is - just clean him up and encourage him for next time.
I would love to know how it goes, and if you chose to implement any of these suggestions. I know you can do it….good luck!