Trotskyists and anarchists frequently accuse the Stalinists of the PCE - and each other - of being responsible for the ultimate defeat of the Spanish Republican forces during the Civil War. How true is this?
More generally, the impression one gets is that the left was far more popular in Spain than the right, with Franco being supported mainly by aristocrats and clergy - how did his regime build popular support, and how did it avoid an insurgency?
The infighting (both with words and sporadically with guns) within the Republican side certainly didn't help their war effort, but I don't think we can blame their loss in the Spanish Civil War on those divisions. The manpower was split relatively evenly between the Nationalists and the Republicans (with the Nationalists taking more of the officers), but the Army of Africa tilted the balance in favor of the Nationalists from the beginning of the war. Soon after, large numbers of Italians and smaller numbers of well-equipped Germans further skewed the Nationalists' numerical advantage. The Nationalists maintained the strategic initiative throughout the war and chose to grind down the Republicans. Given the relative lack of automatic weapons, tanks, and artillery within the Republican ranks it was difficult for them to have much success on the offensive, and the Nationalists were consistently able to counter any Republican advance.
More generally, the impression one gets is that the left was far more popular in Spain than the right
A rough approximation of the sentiment could be gleaned from the 1936 Spanish Elections. The Popular Front got 4,451,300 votes (~47%) while the National Block got 4,375,800 votes (~46.5%), showing a somewhat even split. There was, however, widespread voter fraud on the part of the Nationalists that skew that number in their favor--just how much is hard to determine.
with Franco being supported mainly by aristocrats and clergy - how did his regime build popular support
In popular memory this may be true, but in reality Franco's support was not just amongst the elite. I think Paul Preston covers this best in The Spanish Holocaust (and in his Spanish Civil War), as he details that there were other sources of support for the Nationalists other than aristocrats and clergy. Many Catholics were turned off by the left, particularly given the 1931 changes to how the government treated the Church. While the Church in Spain could be an oppressive institution, the rapid secularization program pursued in 1931 was also accompanied by many petty procedures such as taxing how many times a church bell would ring, not recognizing marriages performed by the Church, and banning religious processions. Large agricultural and industrial concerns supported Franco, but so did many medium and small businesses and farms that were fearful of forced collectivization. Monarchists (of which there were two main groups, the Carlists and the Alfonsists) also supported Franco, and these people came from all walks of life. Traditionalists of all stripes also flocked to Franco's banner. The narrative of the Nationalists being from the elite is not quite accurate.
how did it avoid an insurgency?
The Nationalists secured areas they conquered in brutal fashion. My recent answer on the White Terror should cover most of the basics, but an insurgency was suppressed (rather than entirely avoided) by a deliberate campaign of murder, imprisonment, and intimidation. This began in the earliest days of the war and continued long after it ended.
As always, followup questions from OP and others are encouraged.