Nitrogen is more electronegative, and when reacted, can form a polar bond, in which it basically takes the electron from the hydrogen molecule. This is more stable and thermodynamically favorable.
You could also say that it minimizes the free energy, which is the indicator of whether a reaction will occur spontaneously.