magnesium forms a layer of $\ce{MgO}$ readily on it's surface when exposed to air, thus preventing further reaction, when you put $\ce{Mg}$ in water, which is actually the $\ce{Mg}$ with the $\ce{MgO}$ crest on it, it is essentially inert to water as the oxide crest won't react, and or allow access to the interior where pure $\ce{Mg}$ lies. But if it were pure $\ce{Mg}$ and Water, the result sure will be $\ce{Mg(OH)2}$
Also for a reaction to occur between a solid and liquid, atoms of the solid need to dissolve on the liquid to interact with the liquid itself or a component of liquid as a mixture. It is a fact that $\ce{MgO}$ is not very soluble in water, hence restricting it's interaction with water
In response to comment by Ivan Neretin
IvanNeretin @IvanNeretin , the solubility of $\ce{MgO}$ is $\pu{0.0086g/100mL}$ while $\ce{CaO}$ reacts directly with water, it is the natural property of $\ce{MgO}$ to not to react with water, while $\ce{CaO}$ naturally reacts with water. I can deduce one thing from this $\ce{MgO}$ is stable in water, while as $\ce{CaO}$ is instable, and reacts to form a stable a stable $\ce{Ca(OH)2}$