Diarrhea is definitely unpleasant, but how does it work physiologically?

What causes food and drink to pass through the system more quickly? Is the motion caused by mechanical action of the intestines, or could it be that the intestines somehow stop absorbing fluid? If they can turn absorption on and off, how does that happen?

The BRAT diet (Bananas, Rice, Applesauce, and Toast) is often recommended as a home remedy to diarrhea. The idea is that these bland foods are “easier” to digest than foods with a lot of fat, protein, or fiber. Why are some foods easier to digest than others? Is it related to the size of the food molecules, with small molecules more easily diffusing into the bloodstream?

Is diarrhea a response to fight against infection? Is it effective? How does it work?

Does diarrhea cause damage to the intestines? I could imagine that if stomach acid goes down into the intestines that it could damage all the little intestinal villi that are important in absorbing nutrients. I wonder if diarrhea could upset the microbiome as well.