I tried to look this up from the internet and didn't find anything. I also asked this from my history teacher who didn't really give me a proper answer. Only thing I think I might know about this is that Finland had no other chance and Finland had a good relationship with Germany earlier. But I have no idea why did Germany give Finland to the Soviet Union.
First we must realise that Finland had been part of the Russian empire but declared independence in 1917. Russian wanted to reclaim its territory and so when Germany and Russia were dividing up Eastern Europe during the negotiations as part of the occupation of Poland Russia could snatch the Baltic states and parts of Finland. For the German's this really didn't mean much but it reassured the Russians and Germany may have agreed to provide international legitimacy to Russia's actions.
However the Fins resisted leading to the Winter War which the Fins eventually lost but not before showing up the poor state of the red army. When Germany declared war on Russia, the Fins decided to join in to retake the territory they had lost in the Winter War (this part of the conflict is called the Continuation War).
As the war got worse Germany basically abandoned the Fins leading them to sue for an independent peace.