Based on the Rambam himself, in the introduction to this work, he states that he produced this work in response to a widespread deterioration in understanding the law (halacha) from the Gemara.
Initially once the Gemara was redacted, the Rabbis of the communities of the diaspora (the Geonim) would be available to the masses to help clear up any difficulties in halacha that arose. They would teach these according to their wisdom, and over time collect these in "She'elot u'Teshuvot" (Q&A) works.
It got to the point where the difficulties in understanding the Gemara and paskening halacha were accumulating, and finding authoritative answers was proving difficult, especially as each work was specialised, either on a topic or certain tractates. By the time of the Rambam, he writes that...
...we have been beset by additional difficulties, everyone feels
[financial] pressure, the wisdom of our Sages has become lost, and the
comprehension of our men of understanding has become hidden.
Therefore, those explanations, laws, and replies which the Geonim
composed and considered to be fully explained material have become
difficult to grasp in our age, and only a select few comprehend these
matters in the proper way. Needless to say, [there is confusion] with
regard to the Talmud itself - both the Jerusalem and Babylonian
Talmuds - the Sifra, the Sifre, and the Tosefta, for they require a
breadth of knowledge, a spirit of wisdom, and much time, for
appreciating the proper path regarding what is permitted and
forbidden, and the other laws of the Torah.
Therefore, I girded my loins - I, Moses, the son of Maimon, of Spain. I relied upon the Rock, blessed be He. I contemplated all these texts and sought to compose [a work which would include the conclusions] derived from all these texts regarding the forbidden and the permitted, the impure and the pure, and the remainder of the Torah's laws, all in clear and concise terms, so that the entire Oral Law could be organized in each person's mouth without questions or objections. Instead of [arguments], this one claiming such and another such, [this text will allow for] clear and correct statements based on the judgments that result from all the texts and explanations mentioned above, from the days of Rabbenu Hakadosh until the present.
[This will make it possible] for all the laws to be revealed to both those of lesser stature and those of greater stature, regarding every single mitzvah, and also all the practices that were ordained by the Sages and the Prophets. To summarize: [The intent of this text is] that a person will not need another text at all with regard to any Jewish law. [Trans. by Eliyahu Touger, Moznaim Publishing]
Note how the Rambam is trying to avoid recording any debates. He claims that it takes a depth of knowledge, learning and skill to be able to fathom direct law from the debates of the Oral Law's transmission process. Until then, this hadn't posed a problem due to everyone's level of learning*, as the Torah's transmission was indeed meant to foster this hands-on "debate" style, producing an intimate relationship with the Torah. As beautiful as that was, it can't take precedence over maintaining the integrity of the halacha.
Recording and reducing it stifles the process, and isn't ideal in the same spirt of "לא ניתנה תורה שבעל פה ליכתב" - the Oral Torah shouldn't be written down. Each stage of writing it down has caused it to become more stale, and less innovative. Only "times of great need" would allow such a thing and Rambam was indeed at the precipice of a "time of great need" that only got worse since**.
In answer to your specific question of how did people learn halacha before we had these written-down Oral Torah works, the Rambam addresses this as well:
Rabbenu Hakadosh composed the Mishnah. From the days of Moses, our
teacher, until Rabbenu Hakadosh, no one had composed a text for the
purpose of teaching the Oral Law in public. Instead, in each
generation, the head of the court or the prophet of that generation
would take notes of the teachings which he received from his masters
for himself, and teach them verbally in public.
Similarly, according to his own potential, each individual would write
notes for himself of what he heard regarding the explanation of the
Torah, its laws, and the new concepts that were deduced in each
generation concerning laws that were not communicated by the oral
tradition, but rather deduced using one of the thirteen principles of
Biblical exegesis and accepted by the high court. This situation
continued until [the age of] Rabbenu Hakadosh.
I strongly recommend reading the whole of the introduction as it will answer these questions in more detail and be a spring board for further reading.
tl;dr There was no need for such a work before the Rambam, but due a decline in the level of learning of both the leaders and the average Jew, the time had come for a work that boiled down the law into a set of dos and donts, concise and free of debate.
* although do note that the redactions of the Mishna and the Gemara both represented similar junctures of deterioration in our history
**
Welcome to the age of Kitzur Shulchan Aruchs, Sefarias, and Halacha Lines. We are even training computers to look up stuff for you.