Why does oxalic acid have exactly two water molecules of crystallization?
As @Ivan Neretin states, the crystal structure determines how much water can be accommodated. For example, $\ce{CuSO4}$, cupric sulfate or copper(II) sulfate, may be found as a mineral with three, five or seven molecules of bound water:


Bonattite (trihydrate mineral)
Bluestone (pentahydrate)
Boothite (heptahydrate mineral)


Of course, it can also be heated to form the anhydrous salt.

One could say different crystal forms have room for different amounts of water, or the converse: by adding or removing water, the crystal structure is changed.