Given the result you have stated, if $M, N$ are two surfaces and $\gamma:[0, 1]\to\mathbb R^n$ be the minimizing curve connecting $M, N$, with $\gamma(0)\in M$ and $\gamma(1)\in N$. Then in particular $\gamma$ is a minimizing curve from $\gamma(0)$ to $N$, so it is perpendicular to $N$ by the result that you have stated; similarly it is perpendicular to $M$.
In fact, it is true in a much more general case:
Let $X$ be a Riemannian manifold, $M, N$ submanifolds of $X$, if $\gamma$ is the shortest curve between $M$ and $N$, then $\gamma$ is perpendicular to both $M, N$.
I will outline a proof in the case of $\mathbb R^n$, which can be generalized to any Riemannian manifolds.
Same setup as above: Suppose $\gamma$ is not perpendicular to $N$ at $\gamma(1)$, then we may find a tangent vector $\vec v\in T_{\gamma(1)}N$ such that $\langle \vec v, \gamma'(1)\rangle>0$. We may find a variation of $\gamma$, i.e. a smooth family of curves, $\alpha:[0, 1]\times(-\varepsilon,\varepsilon)\to\mathbb R^n$ such that $\alpha(t, 0)=\gamma(t)$, $\alpha(0, s) =\gamma(0)\in M$, $\alpha(1,s)\in N$ and $\partial_s \alpha(1,0)=\vec v$. We may think of this as a family of curves connecting $M, N$: $\gamma_s(t) =\alpha(t, s)$. Consider the lengths $L(s) =\int_0^1 |\partial_t\alpha(t, s)|dt$. $$\begin{align} \frac{d}{ds} L(s) & =\int_0^1\frac {\langle\partial_{st} \alpha, \partial_t\alpha\rangle} {|\partial_t\alpha|}dt\\&=\int_0^1 \frac{\partial_t\langle \partial_s\alpha,\partial_t\alpha\rangle-\langle\partial_s\alpha, \partial_{tt} \alpha\rangle}{|\partial_t\alpha|}dt\end{align} $$
Now here we may assume $\gamma$ is parametrized proportional to arclength $|\partial_t\gamma|=\ell$, and also $\alpha(t, 0)=\gamma(t)$ is a geodesic $\partial_{tt}\alpha(t, s)|_{s=0}=0$. So evaluating $\frac{d}{ds} L(s)|_{s=0}$, we get $$L'(0)=\frac 1\ell\langle\partial_t\alpha, \partial_s\alpha\rangle |_0^1=\frac 1\ell \langle \gamma'(0), \vec v\rangle <0$$
So near $s=0$, when $s$ increases, the length decreases, which contradicts with the fact that $\gamma$ minimizes the length between $M, N$. So $\gamma$ must be perpendicular to $N$.
The proof in the case of Riemannian manifold is almost exactly the same. With the partial derivatives replaced by connection, and inner product is given by the Riemannian metric.