I recall having this theory quite a while ago. Let's say your diet includes eating powdered sugar donuts in the morning. The gut microbes that feed on it become plentiful. Then when you switch out diets, that particular microbe starts to die out. Then as they die, they release a hormone that causes the gut to signal the brain to crave that particular food type, and this is an evolved behavior for that microbe. And after a while of switching up the diet, those microbes finally get purged, and you don't have as bad of cravings anymore.
At least this is the sequence of events that really makes sense (to me), but I haven't read this in any research yet.