Madison and the Founders felt that the legislative branch was the most important because it was the one that most directly represented the people and it was the one that was least likely to become despotic. These things, added to the fact that it was the only branch that could proactively make laws, made it the first (most important) branch.
To begin with, the legislative branch has the most actual power given to it by the Constitution. It is this branch that can propose and pass laws. Of course, the laws must be signed by the president (with the exception of laws that are passed after a veto is overridden or which the president allows to become law without being signed). However, it is only the Congress that can actually create a law. This makes it more important than other branches.
To the Founders, it was also important that the government should be of the people but should also be prevented from acting despotically. The Congress was the branch that was most directly representative of the people. In addition, its large number of members and its bicameral nature made it less likely to act rapidly and unanimously to oppress the people. A powerful president or judiciary could act much more quickly in an oppressive way. Therefore, Congress seemed both more democratic and safer to Madison and the other Founders.
James Madison referred to Congress, or the legislative branch, as the first branch of government because under the Articles of Confederation (the system of government that pre-dated the Constitution), there was only a legislative branch. The Articles of Confederation, which was the American governmental system from 1781 to 1789, did not have an executive or judicial branch. Each state had one vote in the Congress of Confederation. As a result, the powers of the central government were too limited, and the government under the Articles struggled to raise money (as Congress had to ask the states for money). Congress also could not regulate foreign trade or interstate commerce. After Shays' Rebellion in 1786 and 1787, the weakness of the Articles was even more apparent, and there was a call for a more powerful system of central government, which resulted in the Constitution.