Foamy diarrhea can be caused by various underlying conditions. It may be a result of malabsorption disorders like celiac disease, dietary intolerances, infections in the gastrointestinal tract, or conditions like pancreatitis, irritable bowel syndrome (IBS), and abdominal surgeries.