Any sort of internal conflict would jeopardize war efforts in any country anywhere, which is why past leaders went to sometimes extreme measures to insure unity (Lincoln suspending Habeas Corpus, rationing and propoganda during WW1 and WW2, Japnanese internment, etc.)
So why did those in the Russian Revolution not fear the prospects of crippling their own country and leaving it open for invasion? Yes, they left the war after the revolution but surely it couldn't have been as simple as thinking "oh we'll just leave the war" could it?
One of the crucial aspects of 1917 to realize is that it was not one revolution, but two. The first revolution, the February Revolution, occurred in March 1917 in Petrograd and overthrew the monarchy. This led to the formation of the Provisional Government largely drawn from the Duma, the legislative body Nicholas II had to convene in the aftermath of the 1905 Revolution. The Provisional Government promised not only that it would hold elections to the Constituent Assembly, but it also affirmed Russia's commitment to the war. While Allied foreign governments treated this move with enthusiasm this proved to not be a very popular move. This growing discontent percolated throughout the summer and autumn of 1917 culminating in the October Revolution in November which brought Lenin and the Bolsheviks to power. The Bolshevik's basic platform in the October Revolution with regards to the war was to seek a way out of it. One of the key Bolshevik slogans in this period was "Peace, Bread, and Land" which reflects the charged politics of the time.
As the short summary above indicates, the war was deeply intertwined with the revolutionary politics of this period. Nicholas II's conduct of the war ranging from his taking up personal command of the armies to the mismanagement of the Russian war economy all exposed the weaknesses of the post-1905 imperial system. Fittingly called "constitutional autocracy" by Stephen Kotkin, Nicholas II adapted a form of government that was highly contradictory. There was a legislative body, the Duma, elected on a very limited franchise that could advise the Emperor on key matters and approve his laws, but had relatively little oversight over the running of government. Although this system worked after a fashion up to 1914, it generated a good deal of discontent among Duma members and other components of Russia's small but growing liberal society. One Duma faction, the Kadets (constitutional democrats) not only saw the Duma as a vehicle for a wider transformation of the Russian state into a constitutional monarchy, but some more radical Kadets even envisioned a Russia without a tsar.
The initial outbreak of war did force a type of Burgfrieden within the Duma and most of its members did vote for war credits and other measures to strengthen the war powers of the state. But the conduct of the war brought up earlier discontent with the system. A number of liberal Duma members argued that the setbacks on the front were a sign that the wrong people were in charge of the state and what was needed to fight the Central powers was a more professional and competent leadership. The grumbling started in 1915 but soon turned to open opposition by 1916. One famous instance of this was the Kadet deputy Pavel N. Miliukov reading aloud in a November 1916 Duma session a litany of shortcomings and failures of the state and asking "Is this stupidity or treason?".
Thus by early 1917 there already was a political opposition primed to take over should the right conditions arise. But the wellsprings of 1917's revolutions was much more than in the chambers of the Duma. For both Russia's peasantry and urbanites, the war had lost much of its appeal by 1917. The initial enthusiasm for the war, which was never that strong to begin with in 1914, had very much evaporated with the retreats and various refugees in the Russian hinterland. The state had not helped matters through its management of the economy. Although the tsarist state did manage to create a war industry, no small feat given that one of the prewar industrial heartlands of the empire- the Western Provinces- was a battleground, the war economy had wide-ranging reverberations within the empire. Food prices and other necessary commodities became scarce and fed greater discontent. The extension of conscription to groups hitherto excluded from this added a further element of disgruntlement. The attrition of the front also frittered away the strength and morale of the one institution that had proved to be consistently loyal to the Romanov state: the army. At the officer level, Petrograd's seeming mismanagement of the war and court politics alienated those professional officers from the regime while the lower ranks tended to grow increasingly weary of the war.
Nicholas II thus found himself with very few friends when street riots in Petrograd soon mushroomed into a wider revolution in March 1917. But the Provisional Government's commitment to the war soon proved to be a millstone around its neck. The RSDLP (a Marxist party whose two main factions were the Mensheviks and the Bolsheviks) and other left-wing groups, many of whose leaders had participated in the 1905 Revolution and had been thwarted by counter-revolutionary action, were determined to press their advantages in this charged political environment. Lenin in particular understood on a crude level that arguing for an end to the war was one of the keys to power.
The war itself had a small uptick in popularity after the February Revolution especially among those moderate and left of center politicians who thought that the Germans could be thrown back once Russia's vast reserves and resources had been brought to bear. But this proved short-lived as the nature of the war meant that any victories on the front would be costly and not immediately apparent. The Provisional Government was on the horns of a dilemma in the summer of 1917; it had come to power on the twin promises of alleviating suffering and managing the war better than the Romanovs. But to accomplish the latter, it had to institute methods of managing the economy that were even more draconian than the pre-1917 governments. In promising both victory and a more liberal society, the Provisional Government was in a situation where it could deliver neither.
Lenin and company used the political paralysis of the Provisional Government and wider discontent to their own advantage. The Bolsheviks had a unique Gordian knot solution to the issue of the war: unilaterally end it. As good Marxists, the Bolsheviks were not really interested in fighting what they saw as a bourgeois war. Moreover, during their train trip through Germany on their return to Russia, a number of Bolsheviks were aware of the dire straits of Germany's own domestic economy and the growing discontent of Germany's working classes. Lenin gambled that any concessions granted to the Central Powers would soon be moot since they lacked the resources to hold them and would soon be under the grips of a revolution themselves.
But the formal exit of Russia from the war was easier said than done. Roughly speaking there were two approaches the ruling Bolsheviks had to the war. One approach, championed by Trotsky, was "no peace, no war," in which Russia would unilaterally disengage from the war and tend to its own house. Trotsky's negotiations with the Central Powers on this platform actually infuriated the German and Austrian representatives. Trotsky dropped his "bombshell," that Russia was not going to sign a peace treaty, but was unilaterally leaving the war. Trotsky announced this after a long diatribe on the natures of imperialism that many thought was just a prelude to a concession. This put the Central Powers in awkward spot of whether to continue fighting to gain a proper treaty or let well enough alone and simply take whatever portions of Russia their military could occupy. The exhausted Austro-Hungarian and Ottoman governments favored the latter course, but the Germans resumed operations and would force Lenin to sign the Treaty of Brest-Litovsk. This was the line of approach favored by Lenin and represented the second stratagem of the Bolsheviks to ending the war. By participating in the formalities of a peace, they could tactically strengthen the cause of revolution both at home and abroad. A formal peace treaty was a sign that the Bolsheviks stood for peace while the other signatories continued the war.
In hindsight, most of Lenin's gamble paid off. The Germans found that even maintaining the rough provisions of Brest-Litovsk to be a logistical nightmare and the treaty raised German expectations of final victory far too high. The failures of the Spring 1918 offensives and the continuation of the war denuded much of the glow from the Russian surrender. Although Germany did not fall to a radical revolution, the USPD-led mutinies of the fleet were emboldened by Lenin's example as were other insurgencies within the Austro-Hungarian sphere like Béla Kun in Hungary.
The actors within the two revolutions in 1917 did not ignore the war but instead used the war as a justification for revolution. Many of those who claimed victory in the February Revolution such as the Kadets justified their actions as measures to run the war more effectively. This was not a completely unpopular opinion, especially with German advances in the Baltic, but one whose public support was predicated on achieving results. When these results were not forthcoming, the situation was ideal for a faction like the Bolsheviks to step in the vacuum. Not only did Lenin and company have the benefit of being opposed to the war from the start, they really had no stake in fighting the war to its conclusion. This meshed with the wider Russian public's attitude far better than the Kadets or left-wing supporters of the war like Alexander Kerensky. The Russian general public might not have relished a German victory, but their larger dislike for the war itself was far greater.
For further reading, Alexander Rabinowitch's Petrograd trilogy is an excellent introduction to the shifting political landscape of 1917. Sheila Fitzpatrick's The Russian Revolution is also one of the best brief surveys of 1917 available.