Finland was an Allie of Germany when it looked like the Germans were going to beat the Russians. Once it was clear to Finland the Russians were going to win. They changed sides and declared war on Germany.
That's not exactly what happened...
Finland was a part of the Russian Empire from 1809-1917. During the Bolshevik Revolution and ensuing civil war, many of the areas which had been previously part of the Russian Empire (including Poland, the Baltic states, and Finland) became independent entities.
In Finland this was because the whites defeated the reds... so, although they never were able to install a monarchy, Finland was never incorporated into the Soviet Union and became an independent state for the first time in its history (it had previously been a part of the Swedish Empire).
A contribution to the white victory in Finland was the donation of some aircraft by a Swedish nobleman named von Rosen. Von Rosen's symbol, a blue swastika, therefore served as the roundel of the Finnish Air Force until the end of the Second World War. You can still see the 'von Rosen Cross' in Finnish Air Force insignia even though it's been replaced by a cockade roundel due to the swastika's modern association with the Nazis.
Finland was one of the territories the Soviet Union was looking to 'take back' in the late '30s, along with what it had lost of Poland and the Baltic states. The Soviet Union declared war on Finland on November 30, 1939, but was unable to achieve what it had set out to do (annex Finland) and just made off with some pretty minor territorial gains in the peace treaty signed March 13 1940. This war was known as the Winter War, and it's around this time that Finland purchased 40 some odd Brewsters from the United States (Finland didn't have a domestic aircraft industry (hell, their infantry was using Mosin Nagants left over from the civil war) so they flew whatever obsolete aircraft anyone would sell them the entire war).
Finland thus naturally declared war on the Soviet Union with Germany in 1941. This war was known as the Continuation War (both wars took place during WWII). Finland made peace with the Soviet Union in late 1944 as the war turned against Germany (Finland would have never been able to stand up against a mobilized Soviet Union), under the conditions that they ceded even more territory and revoked Germany's right to use Finnish territory in its continuing war against the Soviet Union. Germany refused to comply with this and Finland had to expel German forces from Finland or else they'd be back at war with the Soviets.
But, Finland remained the only part of the former Russian Empire free from the Soviets after the Second World War.