Invariant theory of variational problems on subspaces of a Riemannian manifold