From a paper by Dr. Anthony H. Cordesman, Burke Chair in Strategy at the Center For Strategic & International Studies:
"The Iraqi security forces should never have been vulnerable to Islamic State (ISIS, ISIL) forces in the first place. As incompetent, political, and corrupt as many officers may have been, reports estimate that the Iraqi Army still had an authorized strength of some 193,400 men towards the end of 2013. While Iraq did not have a real air force, it did have a sizable security force under its Ministry of Interior. While Iraq’s undersized air force was made up some light combat trainers and some 30 armed helicopters, its security forces—which Maliki had increasingly used effectively against the Sunnis—totaled 531,000 personnel, made up of 302,000 regular police, 44,000 paramilitary Federal Police, and 95,000 lower quality security guards in the Facilities Protection Service. While US intelligence estimates put the Islamic State forces at some 31,500 by the late summer of 2014, they probably did not total more than 10,000 full- time fighters when they took much of Anbar province. They were still well under 30,000 when they took Mosul. They also were initially light armed, largely with “technicals”—armored trucks mounting automatic weapons and mortars. In contrast, the Iraqi Army initially had 2 special forces brigades, 1 armored division, 5 mechanized divisions, 3 motorized divisions, 4 infantry divisions, one commando division, and two presidential security brigades—for a nominal total of well over 50 combat brigades. It also had 336 medium tanks (including 140 M1A1 Abrams), 1,194 armored personnel carriers, 188 armored infantry fighting vehicles, 1,334 light wheeled combat vehicles, 48 self-propelled heavy artillery weapons, 138 towed heavy artillery weapons, multiple rocket launchers, and 1,200 mortars."
My own inexpert understanding is that the rank and file recruits to the Iraqi Army came from the local population in the areas where they served as garrisons, though the commanders had been replaced with Shiites loyal to then Prime Minister Maliki. If so, this would tend to make most Iraqi soldiers in Sunni dominated areas, Sunnis.
Kurds are often overlooked, though the 2nd Division of the Iraqi Army which had much of the responsibility for defending the large city of Mosul was largely Kurdish as recently as 2008 and, apparently, at the time of Mosul's fall later, though information about the make-up of the 2nd Division rank and file at that time is difficult to find.
But in January 2014 the Iraqi government under Maliki stopped sending the Kurds the 12% share of oil revenues they had been receiving (itself less than the 17% promised). So the Kurds also had little motive to die for the national government and every reason to hurry back to defend their own territory.
To me, the question is similar to the situation at the time of the October Revolution of the Bolsheviks in Russia. They were few in numbers and only well supplied with (mostly light) arms in St. Petersburg. By contrast, the Russian army, even after massive casualties and desertions, was still huge and immensely well armed. The mechanics of the initial Bolshevik success seem to rest on their support for the aspirations of the mostly peasant rank and file of the Russian army: an end to Russian involvement in the First World War, and official recognition by the new (Bolshevik) government of the land seizures by the peasant families of those soldiers in the villages from which they were drafted. In other words, the ordinary soldiers, who may have been no more than neutral towards the Bolshevik political leadership on average, were not willing to die on behalf of the old government, even though they were not ready to fight on behalf of the Bolsheviks either.
The Bolsheviks also, as documented by John Reed and others, had paved the way prior to the outbreak of violence, with propaganda, infiltration, and liaisons with the rank and file in the Russian army, including the machine gun and armored car equipped units which remained in St. Petersburg serving in security garrisons, whose passive support was crucial for success.
Given what has been published about the ISIS intelligence efforts organized by former Baathists with excellent local ties to the local elites in Sunni dominated areas of Iraq, and the rapidity with which the "conquest" of Sunni dominated areas took place, it seems fairly obvious that the seizures were in large part well arranged in advance, and that the disintegration of government resistance in such areas was voluntary rather than the result of institutional cowardice on the part of the rank and file of the Iraqi army.
The local elites in Sunni dominated areas were exactly the same tribal leaders and wealthy businessmen who had prospered under Saddam Hussein but increasingly been cut out of the power structure (and attendant perks) of the Shiite dominated Maliki government. The Sunni population at large in such areas also had both practical and religious motives for acquiescence in a power grab by a movement purporting to offer protection to abused Sunnis, a religious justification for their own material aspirations, and the elimination of the corruption that had increasingly plagued government and law enforcement under the Maliki government.