So initially, Roman armies were under the command of consuls, right? Each consul led two legions, and each legion was led directly by a legate.
So when the number of armies grew to 20+, the generals didn't really answer to the consuls, since there were only two of them, and two men couldn't be in 20 places at once.
This is my understanding, so bear with me.
So this fact, along with the decline of the senate under Augustus, led to Roman armies owing their allegiance to the general, not Rome... Right?
Overall, why did Roman armies owe their allegiance to their generals, and not the consuls, and by extension, Rome?
First off, the legions would be grouped in armies, the traditional Mid Republican army would be two Roman legions and two allied legions. Each army would be led by a magistrate - a consul, praetor, proconsul, or propraetor. Most of the time when we refer to the "general" we're talking about a magistrate and not the legate. So in addition to the two consuls you had up to 16 praetors (depending on the year) available to command armies. The Romans also often extended the command of a magistrate past their year of office to allow them to continue to command and prosecute a war - this is the proconsul or propraetor. This meant that there was a large pool of elected officials to lead Rome's army.
Regarding Augustus, he knew very well that whoever had controlled the armies could make a play for power and that the senate was full of ambitious men. So he cleverly offered to take up those provinces that held the greatest threat to Rome - which coincidentally held the largest concentrations of legions. Since he couldn't lead multiple armies he would appoint legati ("deputies") for each. There was a precedent for this - Pompeius had governed Spain through legati so he could stay in Rome and manipulate things for the First Triumvirate. As 'deputies', they reported to Augustus - not the senate. He made sure he chose men who were loyal to him and lacked the stature to make a play for the throne.
Prior to that generals informally answered to the senate who could punish them by not ratifying their decisions or denying/stalling any land grants for his men. And any general was also of senatorial rank and would be sitting among them after he gave up his command. Unless he wanted to be a pariah, he knew to respect the senate's wishes.
The question about why the soldiers owed their allegiance to their commanders (who would be consuls) rather than Rome? That's another whole issue particular to the Late Republic and the Empire. Prior to the Late Republic, the army was a militia - the men who met a minimum level of wealth would get called up for a campaign and at the end of it they had farms to return to. This system worked fine for when Rome was only controlling Italy and the wars were local (relatively speaking).
But by the Late Republic, Rome had an empire that ran from Spain to Greece and so you had to travel a lot farther and some of these wars dragged on for years. Men got tired of being frequently called up and began to avoid the census - which meant they became invisible for the draft. Others had been away from their farm so long that it failed which meant they no longer had the property requirements to serve and also no longer draftable. All this mean the pool of soldiers was shrinking dramatically. Eventually Gaius Marius waived the property requirements and accepted volunteers - and a lot of these came from the poor who previously had not been eligible. These men had been surviving hand-to-mouth on manual labour jobs and the army offered regular pay, food, booty following a successful war, and possibly land grants. The latter meant respectability and stability. And the person who would get them that was their commanding officer (e.g. Sulla, Pompeius, Caesar).
These successful generals would inevitably have political opponents in the senate who would oppose them (as honour was a zero-sum game in Rome) and would try to block things like land grants since it guaranteed thousands of clients which would increase the great man's authority and respectability. So when politics would block a law that would give the soldiers land, it's quite expected that they'd support the general when he rebelled against Rome.
Under the Empire, the lesson was quickly learned that whoever controlled the armies would be emperor. The soldiers knew this and not treating them well was an open invitation to an ambitious general somewhere to offer the soldiers a monetary reward/bribe/donation for supporting him.