The Lord Buddha would not set down a rule until the situation demanded it, so the Paali often supplies the origin story about how the different rules came about. Certain characters often reappear in the thick of misdeeds and mischief. For instance, one keeps on coming across Venerable Udaayin or the notorious group of six monks. Their behavior1 required attention and rectification from the Buddha, who then made it into a general rule for all the bhikkhus:
"In that case, bhikkhus, I will formulate a training rule for the bhikkhus with ten aims in mind: the excellence of the Community, the peace of the Community, the curbing of the shameless, the comfort of the well behaved bhikkhus, the restraint of [defilements] related to the present life, the prevention of [defilements] related to the next life, the arousing of faith in the faithless, the increase in the faithful, the establishment of the true Dhamma, and the fostering of discipline."
Later circumstances may have required the Buddha to make amendments or special exceptions and the rule would then have been adjusted accordingly.2 There are also many other minor offences mentioned in the original Paali texts, which have been further enlarged upon by later Commentaries. So the range of rules has become very extensive, and their observance and interpretation correspondingly wide.
Note that it was often lay peoples criticism that brought the monks wrong doings to the attention of the Buddha. (However, also notice how such criticism was often too hasty in blaming all monks rather than just the original delinquent.)
"There are six reasons why a bhikkhu commits an offence: lack of shame; he does not know that it is an offence; he is doubtful but still goes and does it; he thinks that he ought to do something when in fact he ought not; he thinks that he ought not to do something when in fact he ought to do it; he does something without thinking (absentmindedly)." (Nv p.4)2.
"Another drawback resulting from the need for precision in rules is that the more precisely a rule is defined to suit a particular time and place, the less well it may fit in other times and places. The compilers of the Canon, in order to make up for this weakness, thus provided the origin stories and precedents to show the type of situation the rule was intended to prevent, providing principles and models that indicate the spirit of the rule and aid in applying it to different contexts." (BMC pp.15-18)