Metal and reactions with different temperatures of water
You have two reactions, the metal reacting with water and the hydroxide decomposing:

$\ce{Mg + 2 H_2O \rightarrow Mg(OH)_2 + 2 H_2}$

$\ce{Mg(OH)_2 \rightarrow MgO + H_2O}$

The second reaction, for magnesium, sets in around 350°C.  Below that you can get the hydroxide, above it any hydroxide decomposes and you have the oxide.

Heavier alkaline earth metals, and all alkali metals, have hydroxides stable to higher temperatures, making it more difficult to "direct" the reaction to oxide formation.  In contrast, most transition metals lack low-temperature reactivity with water and their hydroxides decompose easily, so they can give only the oxide.