How was funding of research done in the medieval universities?
Your question is based on a wrong premise: There was no funding specifically for research, because there was no research at medieval universities. Initially, they were created as "self-help" groups of students wishing to learn, first and foremost, the practice of law that was becoming more and more important to urban life. For this purpose, they banded together to pay teachers. (You can find detailed accounts of this in the Wikipedia page or the answers to this question on History.SE). This quickly included also canon law, which brought increasingly many theologians to teach at universities (who, as Stephan Kolassa points out in his comment, did make many significant contributions to the knowledge of the time).
As Darrin Thomas points out, the first research in the modern sense (that cannot be described as doing philosophy) was carried out in the Renaissance by individuals not affiliated with any institution of learning, who were funded either through private means (inheritances, church postings that left them ample free time) or patronage -- in particular, by dedicating self-published monographs to various members of nobility. These later organized themselves outside of the universities in learned societies such as the Royal Society (founded in 1660, but the first seems to be the Sodalitas Litterarum Vistulana, founded in 1488 in Cracow). These initially received no funding (apart from the wealth of their members; for example, Robert Hooke, who built many of the experiments for the Society, became very rich by his involvement in the rebuilding of London after the Great Fire), but later received (modest) grants from the government (hence the name, Royal Society). The role of the universities (as opposed to individual researchers, which might or might not hold posts at one) was seen as that of disseminating the new knowledge.
The idea of universities as a place where research should be done (i.e., professors being hired and paid specifically for their research in addition to teaching, rather than research just being what a good teacher did on their own) is a modern one, arising in the beginning of the 19th century with the foundation of the German universities based on Alexander von Humboldt's ideal (which also strongly influenced the new American universities). To quote:
Just as primary instruction makes the teacher possible, so he renders himself dispensable through schooling at the secondary level. The university teacher is thus no longer a teacher and the student is no longer a pupil. Instead the student conducts research on his own behalf and the professor supervises his research and supports him in it.
Much like modern universities, they were funded by the state: A portion of the tax money was distributed among the universities, which distributed their portion among the departments, which distributed their portion among the professors to pay for their salary and any staff or resources they might require for their research. (Needless to say, there was heavy fighting at all levels about how the money was distributed.)
Funding of specific research via grants is an introduction of the 20th century, when technical and scientific innovation increasingly required expensive equipment. Initially, this was done by corporations and private industrialists, but World War II lead to increasing government support of science and technology. This lead to the creation of national funding agencies after the war. (For example, the NSF was founded in 1950, although the German DFG, founded in 1949, actually has their root in the "Notgemeinschaft der Deutschen Wissenschaft" founded in 1920.)
A lot of research during the Middle Ages was funded through the patronage system. Scientist and other scholars would receive financial support from aristocratic families, royalty, and even from clergy. For example, Galileo, out of appreciation of the support of the Medici family, named the moons of Jupiter after several members of the Medici family. Unfortunately, these names did not stick. This is act is similar to a stadium taking the name of a sponsoring business.
Another method of research funding was self-funding. Entrepreneurial scientist would find personal sources of income. Kepler supposedly published horoscopes while Galileo built scientific instruments for income. Scientist who were rich either by birth or through savvy business practice were called "Gentlemen Scientist." Among such gentlemen scientist includes Robert Boyle and Stephen Wolfram
I'm not a History scholar but I think there are two questions since a lot of what we would call research nowadays was conducted, and thus funded, outside of the few universities (like Bologna and Oxford) that existed in the Middle Ages and that were mainly teaching institutions in the fields of law and theology.
Major contributors to "research" funding were:
- The Catholic Church, even indirectly as many scientific discoveries were made by members of the clergy during the long idle hours their occupation offered them.
- Monarchs of various kinds funded work that was likely to put them at advantage in military power, especially in what we would today call engineering, chemistry and ballistics, as well as trade and in particular, navigation that was a lead motivation to study astronomy, mathematical modeling, geometry, as well as agriculture (precursor to today's botany) and other forms of natural resources extraction such as mining. The list wouldn't be complete without arts and architecture that preoccupied reigning powers pretty much everywhere on Earth and that triggered discoveries in geometry, engineering, "classical" physics (that wasn't quite classical yet).
There were also privately or self-funded scholars who investigated occult subjects, such as alchemy and astrology. Astrology in particular was a profitable activity if you counted rich individuals in your "portfolio". These disciplines that seem frivolous to us actually drew a lot of attention and triggered developments that we would today recognizes as scientific discoveries, for example in chemical methods and mathematics.