Is it just because when I don't floss for a long time (few weeks to a few months) the food trapped between my teeth causes bacteria that cause my gums to swell up?
Medical Sciences Stack Exchange is a question and answer site for professionals in medical and allied health fields, students of those professions, related academics, and others with a sound understanding of medicine and healthcare-related sciences. It only takes a minute to sign up.Sign up to join this community
Although there is limited scientific evidence for flossing, it unquestionably does physically remove plaque between teeth, which cannot be removed with the bristles of a toothbrush. If it is not removed, the plaque in turn can cause gingivitis and ultimatly periodontitis (formation of pockets).
To answere your question weather there are other contributing factors :
Flossing possibly stimulates the gums physicaly, and makes them become firmer, but currently there is very little in the way of evidence for that.
Another possibility is that by flossing regularly, you also use simultaneously other means of cleaning teeth, such as regular teeth brushing and mouth rinces)
Source: http://www.ncbi.nlm.nih.gov/pubmed/24353078 (limited scientific evidence)