When you are anxious, some of the hormones and chemicals released by your body in response can enter your digestive tract, where they interfere with digestion. Stress causes spasms in the bowels which also causes pain and discomfort.
Additionally, when anxiety kicks in and we reach our ‘fight/flight/freeze’ response, and we need to escape danger digestion is an unneeded process. Continuing with digestion consumes energy and carrying the weight of undigested food will slow down any ‘flight or fight’ needed, so the body naturally looks to expel this.