Medieval people believed passionately in the rule of law. The tricky part was figuring out what that law was. Medieval universities were both places where the law was taught and where people worked out what the law actually was. This was especially true of canon law.
So what is "canon" law? It's the law of the church--note that the word has only one -n- in the middle and has nothing to do with big metal objects that shoot cannon balls. Whereas theology is concerned with issues of religion (like "how does salvation work?"), canon law is concerned with the governance of the church (like "how old does a man have to be to be bishop?").
You might think, "Well, the law is just what the church says it is," but "the church" was not by any means a single, organized group (as discussed more here). This meant that churchmen spent a great deal of effort trying to work out what canon law involved, working as individuals.
Canon law, like medieval theology, was based on centuries of decisions made by church councils, by popes (including a lot of forgeries attributed to popes), and by church fathers like Augustine and Jerome. Just finding all these decisions was a challenge. Starting in the Carolingian age (ninth century), several scholars started trying to organize canon law, making a coherent body out of messy and often contradictory rulings. This effort, often sponsored by local bishops, increased in the eleventh century.
But canon law really became organized only in the twelfth century, with Gratian, a professor of law at the University of Bologna. He was not commissioned by the pope or anything of the sort; rather, he was trying to create a clear textbook of canon law to teach to the students.
Gratian used the so-called scholastic method, as created by Peter Abelard, to organize canon law. Like Abelard before him, he divided the law into a series of questions, answered both Yes and No, with citations and support on both sides--quotes from the Bible, rulings of councils or popes, quotes from Augustine, and the like. He then used logic and reason to find what he considered the correct answer.
Though his "Decretum" as it was called was not commissioned, it immediately was recognized at the papal curia as an excellent work. From the middle of the twelfth century on, almost all popes were trained in canon law at Bologna before becoming cardinals (and eventually pope). Recognizing the way that law kept changing to meet changing needs, popes issued pronouncements meant to become part of canon law, called "decretals." Legal scholars at the time collected and organized these.
Canon law covered not just the workings of the church but also anything to do with sacraments, such as oaths--which included marriage. The law of marriage was always a major part of canon law (and some wise-acre law students at Bologna would make up questions like, "So what happens if someone's uncle's cousin marries the second wife of…" You get the idea).
The impact of Gratian's "Decretum" is seen in the fact that it continued to be the statement of canon law in the Catholic church until the early twentieth century--when it was not so much superseded as reworked.