I don't get it. They inherited an economy that was in shambles from the Romanovs, they were recovering from a Civil War, they were dealing with Stalin's purges and collectivization, they were in the middle of the Great Depression, and they owed money to a bunch of countries. How the hell do they have the money to do this shit?
Before getting into the meat of this question, some clarifications are in order. Firstly, the end of the Russian Civil War was a little over a decade before the outbreak of the Spanish Civil War. Although the Russian economy was significantly disrupted by the war and civil war, it had to a degree recovered to something approaching prewar indices by the end of NEP. The Stalinist Five-Year Plans (FYP) and collectivization of the late 1920s and early 1930s did create massive disruptions and carried real human costs, they did lead to increased production indices. While these were never as high as planned and the FYP were incredibly inefficient, they did produce results. The FYPs enabled considerable production amidst the Great Depression, a fact that Stalinist media repeatedly trumpeted. The purchase of foreign equipment and recruiting specialists abroad added to the USSR's foreign debts (although nowhere near the level of the prewar tsarist debt), the ruthlessness of the Stalinist economic system meant that it could squeeze the domestic sector to cover these costs. Additionally, the Depression also made it a buyers' market with regards to this equipment.
Additionally, the Purges of the Soviet military were concurrent with the war in Spain. The first arrests of "Trotskyite" wreckers in the Red Army's officer corps began in the summer of 1936 and crested between 1937-1938. So not only did the purge of the military begin at roughly the same time as the war, but the show trials of the military climaxed after the tide had turned against the Republicans.
Although both Franco and his Axis allies in the Civil War portrayed themselves as underdogs against a Soviet behemoth, Soviet military aid was far less than it appeared at the time. The Soviets were certainly the largest supplier of arms to the Republicans and Soviet propaganda stressed that it was the leader of a broad international coalition against fascism. The military aid to Spain was also the largest Soviet military effort since the Civil War, but it was a much smaller aid package, both in terms of men and material, than that which the Germans and Italians provided Franco. Stalin's aid to the Republicans was well within the Soviet's capabilities and was done relatively on the cheap.
One of the features of the FYPs was that it had a strong military component to it. The Polish war scare of 1927 had underscored the relative poverty of the Red Army in terms of equipment and material. As was typical of the FYP, the results often fell short of the ambitious production goals. For example, the first FYP called for 10000 tanks, but numerous problems forced dramatic scale-backs to a little over 4000 machines. Moreover, there were numerous problems with these machines in terms of quality control and other defects. But for all the shortcomings of the FYP, the numbers do show that they did create a very large defense sector by the mid-1930s. In 1931, Soviet industry produced approximately 1200 military aircraft, and that number had climbed up to around over 3000 by 1936. For all of the problems of the FYPs and military procurement, they did create a large stock of material and reserves that the Soviets could send to Spain.
Importantly for Soviet aid to the Republicans, the armament drives of the FYP created large stocks of obsolete and semi-obsolete equipment that the Soviets could send to Spain. Both during the war and after, many Republican veterans grumbled that the Soviets were far more parsimonious with new equipment than either Hitler or Mussolini. To an extent, this critique is correct, especially with regards to artillery and small arms, but the Soviets did also send some modern and near-modern equipment to Spain. The Soviets sent over some 800 relatively modern military aircraft to Spain along with blueprints and materials for the Republicans to construct more within Spain. The main tank of the Republicans' forces, the T-26, not only outclassed the Nationalists' Axis-supplied vehicles, but was also then a front-line tank in the Red Army.
But while the Soviets did part with equipment, some modern and others less so, the price did not come cheap. The Soviet insistence on hard currency for equipment drained the Republicans' gold reserves at an alarming rate. Some Republicans and other anticommunists complained after the war that the Soviets extorted this large gold reserve out of Spain, but there was a sense within the Republican leadership that it was better to spend this gold than let it sit and run the risk of ending up in the hands of the fascist forces. Unfortunately for the Republicans, the Soviets were the only major power willing to sell arms on a massive scale. The prices for Operation X, the first shipment of military equipment to Spain, were around 30% to 40% higher than global prices for similar equipment.
Although the price for these arms was high, it did allow for the Republicans to wage the war. Soviet military aid though never reached that of the Condor Legion, either in terms of equipment or trained personnel. Although pegging the exact amount of manpower sent to Spain is difficult, the best estimates from Soviet sources is that some 3000 military troops were sent to the peninsula. Of these, the overwhelming majority were aircrew and associated support personnel (ca. 800) followed by tank crew (ca. 350) followed by advisors and instructors (ca. 200). Although the Soviets did enable the recruitment of numerous members for the International Brigades, the number of trained military personnel was quite small compared to German and Italian "volunteers" drawn from their armed services. The Condor Legion, for example, had a establishment base of around 12000 men while the Italian Corpo Truppe Volontarie had around 50000 men; figures that were far larger than the maximum estimates of Soviet advisors.
In the end, the Soviet contribution to the Spanish Civil War was a David and Goliath tale, but one in which a much smaller Soviet contingent lost to a far larger Axis one. Soviet assistance mixed both modern and older equipment and the FYPs created massive stocks of weapons for use in Spain. But the prices for this equipment were quite high and never matched the contributions of either Germany or Italy. Stalin fought the war on the cheap and was much more risk-averse to escalating the war than his fellow dictators on the opposite side of the war in Spain.
Sources
Kowalsky, Daniel Lloyd. The Soviet Union and the Spanish Republic: Diplomatic, Military and Cultural Relations, 1936-1939. Ph. D. University of Wisconsin--Madison, 2001.
Payne, Stanley G. The Spanish Civil War, the Soviet Union, and Communism. New Haven: Yale University Press, 2004.
Stone, David R. Hammer and Rifle: The Militarization of the Soviet Union, 1926-1933. Lawrence: University Press of Kansas, 2000.
Whitewood, Peter. The Red Army and the Great Terror: Stalin's Purge of the Soviet Military. Lawrence: Univ. Press of Kansas, 2015.