Batista had already started losing control of the military months prior to Granma's landing. In early April 1956, recently promoted General Ramón Barquín lead a coup to remove Batista from power. The coup failed, and Batista purged the military of Barquín's supporters, and hundreds of officers were hastily replaced by less experienced ones. This would prove crucial to the success of the initial stages of the revolution, as the army failed to contain Castro's forces (that grew out of the 12-20 survivors from Granma's landing) repeatedly.
Batista could have ended the revolution days after it started. Instead he chose to spend the next couple of years antagonizing the populace. His military ineptness, and his erratic and more often than not quite brutal behavior lost him any popular support he may once had. Castro's forces didn't grow significantly during this time, but his movement's popularity exploded. In March 1958, Batista had gone so far that he lost his most important ally: the US. An arms embargo led to further deterioration of the Cuban army, which was heavily reliant on US arms.
A couple of months later, Batista made his worst decision since the start of the revolution: Operation Verano. Ignoring the fact that his army was rotting from the inside, he decided to move against Castro with a force that may have been about 40 times larger than Castro's, but half of them were new recruits. To make matters worst, Batista divided operational control between Generals Eulogio Cantillo and Alberto del Rio Chaviano. The embarrassing failure of a 12,000 strong force against 300-400 rebels further demoralized the military. A few key officers (e.g. Jose F. Quevedo) even switched sides, and at this point Batista's army, while still vastly superior in numbers, didn't really seem like a formidable adversary for Castro.
By the time he fled, Batista had managed to completely lose the confidence of most his officers and deprive his army of its main source of arms. When he fled he also took with him most of the remaining loyalist officers and ministers, and millions of US dollars. Almost everyone that could have resisted Castro after he assumed powered was either off the island or severely lacking in resources. Castro finished the job securing his position by imprisoning or executing whomever was left that could potentially resist him.
However, even without key pre-revolutionary figures to lead them, significant resources or even popular support, a group of Batista loyalists continued opposing Castro. The War Against the Bandits (the Escambray Rebellion) lasted for six years, and it wasn't until it was over that Castro gained complete control.