Question: I can understand how FODMAPs might cause diarrhea, but how do they cause constipation?
Short answer: I don't know. Skip the rest of this post if you're not keen on rambling speculation about FODMAPs and the gut microbiome.
In so-called simple constipation, as opposed to IBS, fiber/FODMAPs sometimes will actually improve symptoms. But let's talk about IBS-constipation predominant (IBS-C), which rarely responds to increasing fiber in the diet, and which we might be attempting to treat with a low FODMAP diet.
There is no final answer to the puzzling question: "how do FODMAPs cause IBS-C?" In fact, it isn't likely that food or food components cause IBS, rather there are underlying problems such as disordered immune function, dysbiosis, visceral hypersensitivity, slow or rapid transit time, etc. Still, reducing the FODMAPs in the diet can help manage symptoms.
Here are a few things to think about. The Merck Manual says "Constipation is difficult or infrequent passage of stool, hardness of stool, or a feeling of incomplete evacuation."
One way FODMAPs affect bowel function is via osmotic activity; in other words FODMAPs have the ability to attract and hold fluid in the gut. If anything, we might expect this to soften stool and perhaps cause urgent, watery diarrhea. That seems to suggest that the osmotic activity of FODMAPs is not the main problem in IBS-C, although it clearly plays a role in people with diarrhea-predominant IBS. (We can't rule out that colonic distention due to increased fluid load in the gut causes constipation through some sort of broken feedback loop in fluid balance physiology, though.)
The other way FODMAPs affect bowel function is via their rapid fermentability and how that interacts with the type, amount, and placement of the resident gut bacteria in people with IBS-C.
Every single one of us is colonized by a unique set of microbes, as unique as our fingerprints. There is some preliminary work now showing that people with IBS may tend toward different populations of microbes than people without IBS, and that people with IBS-C tend to be colonized by more methane-producing bacteria. Limiting FODMAPs in the diet changes the food supply available and affects the microbiome in unknown ways. Using probiotics or antibiotics also affects the type and amount of gut microbes, and can sometimes improve symptoms. How these observations relate to "difficult or infrequent passage of stool, hardness of stool, or a feeling of incomplete evacuation" only time will tell.