Let $F(\phi) = \int_M |\nabla \phi - X|^2$. The Euler-Lagrange condition for $\phi$ (for it to be a critical point of $F$) is that $$DF_\phi (\eta) = \frac d{dt} \Big|_{t=0} F(\phi + t \eta) = 0$$ for all smooth $\eta$. Bringing the derivative inside the integral and applying the product rule we get
$$ 2\int_M \nabla \eta \cdot (\nabla \phi - X) = 0.$$
Integrating by parts we see $$\int_M \eta (\Delta \phi - \nabla \cdot X) = 0;$$
so since this is true for all $\eta$ we arrive at the Euler-Lagrange equation $$\Delta \phi - \nabla \cdot X = 0.$$
Thus every minimizer satisfies this equation. To prove that a solution of this equation is a minimizer, note that when considered as a function of $\nabla \phi$, $F$ is convex; so if we require $\int \phi = 0$ (to remove the symmetry of adding constants) then the only critical point is the global minimum.