In 1917, Germany was at war not only with Russia, but the United States, Great Britain and France. This provided Germany's army with a number of fronts. As the USA joined the Triple Entente in 1917, it was clear that Germany had to win the war soon or not all. Aside from its army, the German High Command also counted on the Bolsheviks to end the war with Russia.
The Russian army had heavy losses in the East after a series of defeats. The army's counter attacks in 1916 had ground to a halt, and by 1917 the Russians were calling for the tsar's abdication. As commander-in-chief of the army the tsar was also losing the support of the soldiers. That much became clearer when they began to join the Petrograd Soviet. With grain shortages and military defeats, most in Russia called for peace with Germany. In February the tsar abdicated the throne, and the monarchy effectively dissolved.
Before February the Bolsheviks had been in exile. Their most prominent party member Lenin was in Switzerland. This left them outside Russia when the king vacated the throne. With Europe at war, it was not an ideal period for international travel.
With the demise of the monarchy a vacuüm had been left in Russia. It was left to Kerensky to fill that vacuüm before the constituent elections. Kerensky openly supported maintaining the Russian army's front in the war, and was not about to begin peace talks with Germany.
Lenin's policies were the opposite. He made it clear that his party did not support the war in Europe. As such, Lenin emerged as somebody the German High Command could bargain with. For sure they were not communists, or left wingers of any variety, but winning the war in Europe was for them the priority. If there was a party in Russia that would begin peace talks with the Germans, then they could potentially end the war on one front and reinforce their armies in the West. With Lenin as party leader the Bolsheviks were that very party.
So the German High Command began discussions with the Bolsheviks regarding a potential passage back to Russia. They agreed for Lenin to pass through Germany via railway routes. The trip took Lenin, and other members of his party, to naval ports. They boarded a boat that took them to Sweden, and from there Lenin would proceed to Russia.
Lenin arrived at the Finland Station in Petrograd in April. Crowds cheered as the Bolsheviks met up with the Petrograd Soviet members. Now the revolution began in earnest, exactly as the German officers had expected. Lenin pledged to pull Russia out of the war as soon as possible.
Aside from the train trip, the high command also financed the Bolshevik Party in 1917. Finances were provided for them until it was revealed in Russia that the Germans were financing the Bolsheviks. This provided opposition parties with some propaganda scope as Lenin had almost become a German spy.
When the Bolsheviks seized the Winter Palace in October, Lenin established the communist regime. Then the Russians began peace talks with Germany after October. Trotsky met with the Germans at Brest-Litovsk. By 1918 they drafted the Treaty of Brest-Litovsk that effectively surrendered much of Russia's territory in Eastern Europe to Germany. The treaty ceded Russian Poland, parts of the Ukraine and the Baltics to the German Empire.
Lenin had delivered what he had promised, both to Russia and the high command of Germany's army. With Russia defeated, Germany reinforced its Western armies for new advances that were later halted. Had they not supported the Bolsheviks, the October Revolution might not have happened.