It's the Haddith where most of this stuff comes from, and the interpretations of various imams.
In many ways, it's similar to Orthodox Judaism (in the journey, NOT the destination). Jewish Rabbis spent a lot of years building up a "hedge" around the law of the OT. It's in the various rabbinical teachings that you get the statutes like no flipping a light switch on the sabbath because that would be striking a fire, or taking more than 40 steps breaks the sabbath, etc.
Imams have done a similar thing by taking the Q'ran and Haddith and expanding on them to create Sharia. The end product is completely different, of course (I am NOT accusing orthodox Jews of being anything like militant Wahabbists), but the method by which the extreme forms of each faith were reached is similar.