This would be more of a chemistry question. Remember magnesium has a charge of 2+, and would need to hand off its two extra electrons. Fluorine can only take one electron at a time, so there needs to be two fluorines to take one magnesium's 2 electrons.
With lithium, it has a +1 charge, so it has one extra electron, which it can hand off to just 1 fluorine atom.
Another way of looking at this is:

+ 2

= MgF2 (the charges must balance out to zero)

+

= LiF (the charges balance out to zero)