Is there a rule for when a monster qualifies for a bonus feat in Pathfinder? For example, among small elementals, water elementals have no bonus feats, earth elementals have one, and air and fire elementals have two, but I can't find any rule reference for why this would be. Is there one, or is it purely arbitrary by the designer?
Bonus feats are assigned by the monster designer to represent traits he feels every member of that monster race should have. In your example, those elementals ALWAYS have those bonus feats at every size. Air Elementals are always quick as the wind (Improved Initiative) and deadly accurate (Weapon Finesse). These are intrinsic to nature of air elementals, and so can't be replaced when customizing these monsters (normally, a GM can obviously override this). Earth Elementals are super-dense, able to push aside normal creatures like chaff on the wind. Fire Elementals are basically just hot air elementals, to be fair, and have the same bonus feats.
Take note that each of the four elementals you listed have exactly three special traits that set them apart. The air and fire elementals have two that were expressed as bonus feats and one as an extraordinary quality. Earth elementals have one bonus feat and two Ex qualities. None of the water elementals' special traits worked as a bonus feat, so all three were Ex qualities.
When designing your own monsters, if you want to give the entire race a specific effect that can be represented by an existing feat, it's much easier to understand that effect when it's listed as a bonus feat, rather than writing it out as a new quality. That's what the designers did with the elementals. There's no rule for how many bonus feats a monster can or should have, just as there's no rule for how many qualities a monster should have. They should have enough qualities and bonus feats to represent them mechanically; no more and no less.
Please note that this answer pertains ONLY to bonus feats; all the other feats listed in a monster's description are feats the designers feel "average members" of that race will choose at those numbers of hit dice and aren't anything intrinsic to those monsters. Also note, for Conjurers and Summoners, that means there are members of those races with different feat selections - only the bonus feats are immutable. How hard it is to summon a non-average member of that monster race is entirely up to your GM, but it should be possible, at least.
There is a rule for adding feats to monsters, and that comes from monster advancement when increasing the hit dice of creatures.
Next, give the creature additional feats. Creatures gain one feat at 1 Hit Die and one additional feat for every 2 Hit Dice above 1. Most additional feats should be focused on increasing the creature's combat abilities, but metamagic feats and skill feats are also possible choices depending on the creature's role.
For the elementals specified in your question, gatherer818's answer is accurate. Designer's add feats to creatures to match the flavor for that monster.