Let $\gamma:(-a,a)\rightarrow \mathbb{R}^3$ be a local arclength parametriziation of the curve in question.
This means $|\gamma^\prime(t)|^2 =1$ for every $t$ and, consequently, $\langle \gamma^{\prime\prime},\gamma^\prime \rangle = 0$. The claim is equivalent to showing $ \gamma^{\prime\prime} = 0$ (why?).
Now since the curve is a geodesic in the two surfaces -- assuming you know the geometric consequences of this statement -- you know that the tangential component of $\gamma^{\prime\prime}$ in $M_1$ vanishes. Let me write $(\gamma^{\prime\prime})^{M_1;T}$ for that component.
I.e. if $e_1(t) $ is a normal vector to $\gamma$ in $M_1$ of length $1$,
$$(\gamma^{\prime\prime})^{M_1;T} = 0 =\langle \gamma^\prime,\gamma^{\prime\prime}\rangle \gamma^\prime+ \langle e_1(t),\gamma^{\prime\prime}\rangle e_1(t) $$
Since (see the introductory remark) $\langle \gamma^\prime,\gamma^{\prime\prime}\rangle=0 $, also
$$ \langle e_1(t),\gamma^{\prime\prime}\rangle = 0$$
The same is true for a vector field $e_2$ of length $1$ along $\gamma$ which is normal to $\gamma$ in the second surface, $M_2$, say.
If the surfaces meet transversally, $e_1$ and $e_2$ are linearly independent, and together with $\gamma^\prime$ they span $T_{\gamma(t)}\mathbb{R}^3$. The claim then follows by elementary linear algebra.