At the simplest level, the same reason that Hanoi won Vietnam. They were not undivided, but their allies and them were focused on winning the war. The Republic was saddled with the Soviet Union, which spent more time looting the treasury and purging Trotskyists and ordering damn fool foolish offensives that the Republic could not sustain.
Wars are not won by whichever side is less morally dubious, they are won by the side that puts greater focus into superior logistics, strategy, and exploitation of the political factor in war. Franco did all of this. He made very good use of real Republic atrocities and the USSR's aiding the Republic, downplayed his own and that of his Fascist and Nazi allies like Guernica, and exploited that the Catalans, among others, were as likely to fight the Republic as they were Franco, where he fought and executed the POWs of all of them with impartiality. In particular the Republic's free targeting of the Catholic Church, and the realities that its sole major foreign state sponsor was the Soviet Union, in a climate of proto-Cold War against the Stalin regime, were the major elements held against the Republic.The execution of nuns and priests did happen, though it was less gruesome than Franco claimed it to be, and was the reflection of the overmighty position of the Catholic Church in Spanish politics. Revolts in Latin America reflected the same spirit of anti-Clerical and anti-Church violence, for similar reasons of social structure.
Initially it was more of a Madrid political system than strictly a Soviet proxy, but two years into the war the extension of the Purge and the ever-greater reliance on Soviet weaponry led the major Soviet advisors to insist that the amateur generals of the Republic conduct their late-war offensives, especially the Battle of the Ebro. Franco, as a warlord with an army that was spared the difficulties of fighting a state and winning a war could focus on the war much more directly, and held his allies against de Rivera and other figures who could present a strategic threat. The Right held together as a set of warlords and armies, the Left had the power of the state, but could not square the issues of Catalan and Basque separatism (and in the Catalan case there were further divisions among Catalans to compound the issue, the POUM was not the only Catalan movement but it was the most prominent "Trotskyist" movement), waging and winning a war, and maintaining the state at the same time as it balanced the conditions of Soviet aid.
The war's protraction told on both sides, but Franco had the more tactically skilled allies in the form of the Germans, and greater numbers if no great skill in the presence of the Italians. The Soviet numbers were smaller, with Stalin's priorities the destruction of the Trotskyists. Soviet aid came with much firmer strings than that of Nazi Germany and Italy, with the Nazi contingents smaller but effective out of proportion to their numbers. Italy put more into the war than Germany did, but its army displayed feebleness early and its lavish technology could not fully compensate, nor for the morale issues caused by the great defeat at Guadulajara.
Guadulajara was a good example of how the defensive war worked in favor of the Republic. In a case where the Nationalists had more weaponry, mostly of Italian manufacture, a combined Italian-Nationalist force that vastly outnumbered the Republic, and the ability on the offensive to set the pace and location of the offensive, but the Italian army's poor leadership and morale meant that its offensive was half-hearted at best and poorly done, tactically. The Republic by contrast made full use of its resources and when it grasped how feeble the Italian army actually was, launched a counterattack that gave the Italians stiff resistance that culminated in a rout of its armies, and in the destruction of the armored weaponry at its disposal by the B-T tanks at the disposal of the Republic.
As long as the Republic waged a more static campaign, all of its strengths were played up, while Franco's armies struggled to capitalize on the advantages of superior air power and his troops' greater military experience was snarled in urban and siege warfare, which is a great force equalizer. Unfortunately for the Republic, Soviet advisors insisted starting in 1937 that a defensive strategy at Madrid wasn't good enough. So the Republic was committed to a set of strategic offensives that where it won, it won pyrrhic victories, and each further decimation of its army combined in the final shattering defeat in 1938. Zaragoza is the best example of the broader trend.
In the Zaragoza campaign the Republic committed major resources. It did manage to smash the Nationalist positions in the Belchite region in particular, but all that did was bleed it heavily and it made no deeper dent into Nationalist lines. At Guadulajara, the Republic's strengths were in effect. In Zaragoza, the army proved cumbersome and suffered a poorly structured command structure, and its tactics were no more adept than the Italians it soundly defeated. Against the Nationalists, this could make local gains on a small scale, but it was not a deeper threat, and it set the pattern of the later war.
The shift to the decisive offensives culminating in the Ebro meant that an army without the logistical basis to conduct strategic offensives aimed at a decisive victory, accustomed to relatively short supply lines and smaller-scale offensives was committed to something beyond its power to bear. It might win at the tactical level, as in the Zaragoza Offensive, but the result was massive losses for gains that could not be held, which the Soviet advisors responded to by deciding a larger version of the same failure of a strategy was a guaranteed success. The ultimate result of this, the Ebro battle, shattered the Republic beyond repair, leaving Franco the simple on paper idea of mopping up the last holdouts. The war, in strategic terms, was won at the Ebro, though the fighting and mopping up by Franco lasted into 1939.
The Ebro itself was the largest battle of the war, which compounded all the defects of the Republic and its allies, while playing to the strength of the Nationalists. Franco understood how to direct a large combined-arms battle better than the Republic did, and commanding forces of the size of those at the Ebro was beyond the capacity of the Republic's military command. It was the kind of warfare that would be seen again in Monte Cassino, Normandy, and Leningrad, a static campaign dominated by the new kind of firepower, and an approach reliant on attrition, which meant that the weaker force with the lesser ability to sustain a battle was the one most likely to break. And break the Republic's army did.
The Republic had plenty of fine weaponry courtesy the USSR, it had plenty of (Communist) international support. The Republic had more tanks, and better tanks, than did Franco. The BT model tank, the majority of that available to the USSR in the Barbarossa campaign, was better than anything Franco or the proto-Axis duo had to offer their own armies. It suffered from the doctrinal effects of the Purge, shoddy Spanish tactics, and the sloppy maintenance of both Soviets and Spaniards, and the reality that a tactical reverse in using a new and improved weapon meant execution as part of the overall purge of the Armed Forces. It had no shortage of soldiers in its ranks. What it had shortages of were people with the skill to use all of this well and allies focused on the war, as opposed to persecuting 'heretics' as the first priority. The Soviet Union in this case was far more of hindrance than a help. Hitler and Mussolini, especially Mussolini, put effort into trying to fight and win the war. Mussolini's army was no better in this war than it was in World War II, one of the few decisive offensive victories of the Republic was won at the expense of an Italian army that suffered much the same leadership defects that would lead to Beda Fomm and the failure in Greece. This defeat stung Franco, but it did not cripple him.
The Republic's defeats were more destructive because Franco's allies gave him the heft to recoup its losses, the absence of a unified rear zone and focus on winning the war meant that the Republic and Catalonians were defeated in detail. Having the USSR focused on the POUM and the Trotskyists over the Germans, Italians, and Franco and devoting a significant proportion of nominal frontline strength to destroying the POUM did not help matters either, as it meant that the Republic's armies were weakened domestically, in terms of reliance on the USSR, which did not focus on a war suited to Spanish ends so much as Soviet prestige.
Very much the same kind of mistakes the USA made in Vietnam, and the role of Soviet advisors can, in a grim irony, be compared at points to US roles in that conflict. By contrast, the German airmen at Guernica did more effective elements for Franco, and so did the Italians, their major defeat aside. Even the difficulties with the Phalange and the reactionary monarchists and Catholics did not deter Franco during the war, he understood the merits of a singular chain of command and limiting the feuds his side had and went into bloodier elements with after his victory during the war. The Republic and the USSR did not do the same.
Franco was a very bad man, but he was better at waging war than the people the Republic found to fight him. When societies decide to settle things on the battlefield, the better general wins.
Sources:
https://www.amazon.com/Battle-Spain-Spanish-Civil-1936-1939/dp/014303765X
https://www.amazon.com/Spanish-Civil-War-1936-39/dp/0394555651
Thank you all for the answers, really appreciate it.