As far as I know Universities were founded by the Emperor (or different Monarchs?) or the Pope and obviously enough they exercised some powers over the instutions. I remember Thomas Aquinas' teaching was condemned for a while and that the leader of the University (Chancellor instead of rector as we nowdays call him, if we're not English) was appointed by either the Emperor or the Pope. But in present days there is full academic freedom, and the University can even appoint its own leader (this might not be true for all countries, but I probably is for EU ones). So when and why there was a transition?
In medieval Europe, universities developed out of cathedral and monastic schools. Interest in learning, in particular law and canon law, necessitated growing these institutions beyond the scope offered by cathedral and monastic schools. At first they were set up akin to guilds or corporations, where there was a self-determined hierarchy who managed funds, employees, and clients (this is way simplified). In order to gain stability and security, and to help navigate things like the University of Paris in 1229, universities set up charters and treaties with local governments. In some cases, these universities received additional charters of rights and privileges from royal and clerical authorities - e.g. tax exemptions, land grants, appointments to influential positions. Soon after, universities began to be founded by royal and local governments to meet the demands of the people.
These medieval institutions are the forebears and inspiration for many modern university systems. Sorry to break it to you, but there never has been "full academic freedom." You most likely won't see anything else like the Stanford Prison experiment, the Tuskeegee experiments, or much of the academic literature coming out of nazi Germany. Social norms have always prohibited and/or challenged controversial research, whether it be testing on animals or Aquinas' theology.
Politically, in the UK, for example, the university system is financed primarily by the government, and as such is subject to things such as the Education Reform Act of 1988, which places certain strictures onto universities. In the US, most state schools receive a large portion of their funding from state governments, so you end up with oversight from bodies such as the California Postsecondary Education Commission (though it is now closed) or the Texas Higher Education Coordinating Board. The University of Texas system has a permanent endowment of $20 BILLION. Even in a smaller state system, such as Michigan, their endowment is over $9 BILLION. Oxford and Cambridge each have endowments of almost £5 billion. These university systems are far too important for local, state, and national infrastructure to not include some government influence. At Oxford, for example, the university is practically run by the Vice-Chancellor, Andrew Hamilton, a long-time academic. However, the Chancellor, the titular head, is Chris Pattern, a lifelong politician. I'm not trying to make any claims about Oxford or any other university or political system beyond that universities and governments have always been interconnected and that this has influenced the way that universities functioned.
Here are some books that may be of interest to you:
Charles Homer Haskins. The Rise of Universities (1923) - an oldie but a goodie.
Oxford's History of Universities - a serial publication
Roy Lowe. The History of Higher Education (Routledge, 2008)
Richard Kirwan. Scholarly self-fashioning and community in the early modern university (Ashgate, 2013)
Russell L Friedman. Intellectual traditions at the medieval university : the use of philosophical psychology in Trinitarian theology among the Franciscans and Dominicans, 1250-135 (Brill 2013)
Hope this helps a little. Happy reading!