The actual war and peace declarations are random, but there appear to be some modifiers based on how well or poorly a faction is doing. A faction that's strong seems more likely to start a war with another strong faction, and a weak faction is more likely to make peace with other factions. Factions already at war also seem to be less likely to declare additional wars, but it still happens frequently enough. That tends to keep the situation at least slightly balanced, but one faction can still conquer another, and there's enough randomness that practically any combination of wars can happen.
I don't know if the math behind it is accessible in the various editable text files or not, but it seems like the modifiers should be adjustable for modders. There are probably several modders who could give detailed formulas for the odds of declaring war or peace, but the PC with my copy of the game isn't connected to the Internet (no phone or internet connection on that floor of the building), so I can't check it from here, and I'm less familiar with the files than practically anyone else who's made mods (I've only done a couple of minor tweaks).