Q:

Why is the US president commander-in-chief?

Democratic governments are often set up in such a way that no single person holds too much power, even the president/prime minister/etc. 
In the US, you e.g. have the Congress. This means that if the president wants to do some crazy thing tomorrow, they can stop him.
But why then is the US president commander-in-chief? Surely the possibilities to do crazy things are much more vast when it comes to militant operations than when it comes to complicated legislature. 
So what is the rationale behind using the congress to prevent the US president from causing unwanted harm, but then allow him full (or, near full*) control of the freaking army?
*The secretary of Defense has a lot of power as well (e.g., needs to cosign nuclear attacks), but .... this person is appointed by the president!....

A:

Article II, Section 2 of the United States Constitution states:

The President shall be Commander in Chief of the Army and Navy of the United States, and of the Militia of the several States, when called into the actual Service of the United States; he may require the Opinion, in writing, of the principal Officer in each of the executive Departments, upon any Subject relating to the Duties of their respective Offices, and he shall have Power to grant Reprieves and Pardons for Offenses against the United States, except in Cases of Impeachment.
(emphasis mine)

History.org has an article explaining the rationale of the framers of the Constitution. It's mainly a constitutional role, and the article goes into details on the history on how it came about.

The idea that a civilian should control the military was critical in the debates that created the Union.
[ ... ]
Earlier, on May 15, 1776, the Virginia Convention asserted in the Virginia Declaration of Rights the primacy of civilian control: "In all cases the military should be under strict subordination to, and governed by, the civil power." The federal president would be not a part of the military but an elected civilian with supreme power over it.
[ ... ]
Although Congress has the power under the Constitution to declare war, raise troops, and control military funding, presidents long ago began to assert their presumed right to commit troops to "defend and protect" the nation and its interests. Citing their constitutional role as commander in chief, presidents have used the armed forces more than two hundred times outside the United States.
(emphasis mine)

A:

To add to Panda's historical answer:
Anyway you design your constitution, there will be a commander in chief of the army, because when there is time pressure, you cannot wait for several people to discuss the situation and vote. That is why in almost every country in the world, the executive power is in the hands of one person: a king, a dictator, a president, a prime minister...
Even in the ancient Rome, under the Republic, when they hated so much to concentrate every power in the hands of one person that they had two consuls, there was a special law allowing them to give every power to someone in case of emergency.
The problem is, if you have no head of State which is also commander in chief, then in case of emergency there is a huge risk you forget about your constitution and you just give every power to anyone who seems able to save the country. 
It may be argued that it is wiser to have someone with extended, but bounded, powers over the army that will not be increased at any time, than to have exceptionnal laws. Indeed, people are not used to exceptionnal laws, and do not know how to protect freedom in those circonstances.

A:

Democratic governments are often set up in such a way that no single person holds too much power, even the president/prime minister/etc
...
So what is the rationale behind using the congress to prevent the US president from causing unwanted harm, but then allow him full (or, near full*) control of the freaking army?

Article I, Section 8 of the Constitution states that

The Congress shall have power to... declare war...

This was touched on by Panda's answer in passing. However, I believe this is the crucial section that answers your question. As already shown by the answers by Panda and Distic, it is very important that one person leads and controls the army. However, in the case of the U.S. Constitution, that one person is the elected executive of the government.
However, in keeping with the ideas of checks and balances, the President (according to the Constitution) is the commander-in-chief of the army, but Congress has the sole power to declare war. So while the President leads the military, the Congress authorizes the war. That is how the Constitution prevents unilateral actions by the military's commander-in-chief.

