The people weren't trusted
It'll take a bit to get to the titular statement, as we need to discuss the history leading up to the Constitution to understand and justify it.
Between the war for independence and the ratification of the US Constitution was a span of several years. The states were organized into a nation under the Articles of Confederation for this span. It was a near-catastrophic failure.
Perhaps the most important reason for this failure is that the Articles were designed to create an extremely weak federal government: there was no ability to enforce federal laws, no federal judiciary or courts, no ability to collect or levy taxes, no regulation of trade, and amendments needed unanimous consent from all of the states. This quickly led to problems as there arose national-scale problems that the federal government had literally no power to deal with, and states routinely subverted or outright disregarded federal laws and each other with impunity. The unanimous consent on amendments was a death knell, preventing the implementation of desperately needed changes. Things got so bad that a rebellion in Massachusetts arose, and there was nothing the government could do but sit back and cross its fingers.
So the federal legislature authorized a convention to discuss and propose various amendments to the Articles of Confederation that could resolve the issues at hand. The members, however, came to the conclusion that the Articles were essentially impossible to save, and so they decided to just write an all new constitution. This ultimately gave us the Constitution we have today.
The lessons learned from the Articles, and their great failure, guided the construction of the new one. They created a bicameral legislature that would create a form of degressive representation: the House would be proportional to population, and the new Senate would be a body representing each State equally, much as the Congress under the Articles had been, and each chamber was required to consent on legislation. Thus the complaints of insufficient representation of the people was addressed via the addition of the House, and the Senate retained the equality of the states, offering the smaller states a bulwark against the masses (who would primarily be in cities and heavily populated states, and so would have diverging interests from more rural or smaller states and peoples).
However, this did not quite satisfy the Southern states, which were largely rural agrarian with low (white male) populations but lots of slaves. The states that depended on slavery could foresee the inevitable and quick death of the system under a system that was apportioned with respect to the free (white male) population, as it was clear they could not possibly force a direct protection of slavery into the constitution. This leads to the compromise covered in pjc50's answer: the basis for representation in the House would include three-fifths of the slave population. This elevated the amount of representation of the slave states enough that they could expect to readily subvert or block any attempts to weaken or directly abolish slavery.
But this was still not enough. Remember, the federal government was extremely weak under the Articles of Confederation, and that was the primary problem they were working to fix. So the federal government was now going to be stronger, possibly even strong (how strong the federal government should be has always been a bone of political contention in the US, from day one to today). And there was going to be a President to run the whole thing and execute the laws. And the framers saw lots of problems in a direct popular vote for the President.
The first problem—and the only one we need to go into to answer your question—is that the US at the time was mostly rural agrarian and sparsely populated. And there were no telegraphs, or telephones, or trains, or anything faster than horses. News as such traveled slowly, and the populace of each state was largely isolated from each other. And most of the people who could vote were only expected to be knowledgeable of local matters, and deeply preoccupied with time-consuming labors. So how could we trust all of these poorly-informed voters, with no time to spare to really delve into the political issues at stake, to pick someone to lead a whole nation?
Their answer is that we couldn't. The people would really only know those people relevant to their own area and state, and the wants and needs of that area and state, and that would be disastrously divisive on a national scale. So they concocted the idea of the electors. Rather than have the people vote for a President directly, they would instead vote for electors, and the electors would vote for the President. These electors were envisioned as well-educated men, well-versed in national affairs, the greater national picture, and the Presidential candidates in particular. This would allow them to make the well-reasoned and informed decision on who should be President that the framers believed was necessary, while still being sourced by the wills and desires of the people themselves.
This, then, is the answer to the question you ask: at the time the US Constitution was written, the people were not trusted to be able to make a collective, national-scale decision due to having insufficient exposure and time to put in the proper level of consideration of national issues. So instead we pick electors who do have the knowledge and time necessary, and who we have some trust in, to do the job for us (the people). As you can already guess, historical momentum has led the system to simply never correct for all of the Framers' assumptions being violated: the states and peoples are now deeply integrated, news travels in minutes to all corners of the nation (and world), the people as a whole are ridiculously well-informed and well-educated (compared to the standards at the time the Constitution was written), you can physically cross the entire country (which is now much larger than it was then) in a matter of hours, and party loyalty is the only qualifier for electors.