Let $(M,g)$ be a Riemannian manifold and $G$ a compact Lie group acting freely and isometrically on $M$.
Let $\pi \colon M \to M/G$ be the projection to the orbits.
Using the metric, we get a orthogonal space $\mathcal{H}_x$ to the vertical space, defined by $\mathcal{V}_x := \ker d_x \pi$.
Both spaces form a smooth subbundle of $TM$, the horizontal bundle $\mathcal{H} \subset TM$ and the vertical bundle $\mathcal{V}\subset TM$, with $TM =\mathcal{H} \oplus \mathcal{V}$.
Having a smooth function $f \colon \mathcal{H} \to \mathbb{R}$, which is invariant under the action of $G$ by differential, can we extend it on all of $TM$, by $f(Z) = f(Z_{\mathcal{H}})$, such that it remains a smooth function?
Yes, since the projection $p_H:TM\rightarrow {\cal H}$ is a differentiable map. You can show this by considering a trivialization $(U_i)$ of $TM$, the restriction of $TM$ to $U_i$ is parallelizable, you can find vector fields $(e_1,...,e_m,e_{m+1},...,e_n)$ which does not vanish on $U_i$ such that $(e_1,...,e_m)$ generates ${\cal H}$, (they can be determined by the infinitesimal action of $G$ on $U_i$, take $u_1,...,u_m$ a basis of the Lie algebra of $G$ and set $e_i(x)={d\over {dt}}_{t=0}exp(tu_i).x)$ and $(e_{m+1},...,e_n)$ generates ${\cal V}$ (can be obtained by considering vectors fields $f_{m+1},...,f_n$ on $U_i$ which are linear independent, and such that for every $x\in U_i$, $(e_1(x),...,e_m(x),f_{m+1}(x),...,f_n(x))$ is a basis of $T_xU_i$ and take the orthogonal projection of $f_i$ on ${\cal V}$), then on $U_i$, $f\circ p_H$ is differentiable.