[proofplan]
The forward implication is the fibrewise linear-algebra fact that an [orthogonal projection](/theorems/437) is idempotent and self-adjoint with respect to the [inner product](/page/Inner%20Product). Conversely, a self-adjoint idempotent decomposes each fibre as the orthogonal direct sum of its image and kernel. The remaining point is smoothness: because the rank of a smooth idempotent is locally constant, the fibrewise images form a smooth subbundle. Once this subbundle is identified as $F=P(E)$, the fibrewise decomposition shows that $P$ is exactly the orthogonal projection onto $F$.
[/proofplan]
[step:Verify the fibrewise algebraic identities for an orthogonal projection]
Assume first that there exists a smooth subbundle $F\subset E$ such that $P$ is the fibrewise $g$-orthogonal projection onto $F$. For each $p\in M$, define the orthogonal complement
\begin{align*}
F_p^\perp:=\{u\in E_p : g_p(u,f)=0 \text{ for all } f\in F_p\}.
\end{align*}
Thus, for every $p\in M$, each vector $v\in E_p$ has a unique decomposition
\begin{align*}
v=f+a
\end{align*}
with $f\in F_p$ and $a\in F_p^\perp$, and $P_pv=f$.
Fix $p\in M$ and $v\in E_p$. Write $v=f+a$ with $f\in F_p$ and $a\in F_p^\perp$. Then $P_pv=f$, and since $f\in F_p$,
\begin{align*}
P_p^2v=P_p f=f=P_pv.
\end{align*}
Hence $P_p^2=P_p$.
Now fix $v,w\in E_p$. Write
\begin{align*}
v=f+a
\end{align*}
and
\begin{align*}
w=h+b
\end{align*}
with $f,h\in F_p$ and $a,b\in F_p^\perp$. Then $P_pv=f$ and $P_pw=h$. Since $F_p$ is orthogonal to $F_p^\perp$ with respect to $g_p$,
\begin{align*}
g_p(P_pv,w)=g_p(f,h+b)=g_p(f,h).
\end{align*}
Also,
\begin{align*}
g_p(v,P_pw)=g_p(f+a,h)=g_p(f,h).
\end{align*}
Therefore
\begin{align*}
g_p(P_pv,w)=g_p(v,P_pw).
\end{align*}
Since $p$, $v$, and $w$ were arbitrary, the required fibrewise identities hold.
[/step]
[step:Decompose each fibre into the image and kernel of $P_p$]
Assume conversely that, for every $p\in M$, the map $P_p:E_p\to E_p$ satisfies $P_p^2=P_p$ and is self-adjoint with respect to $g_p$.
Fix $p\in M$. Define the fibrewise image and kernel by
\begin{align*}
I_p:=\operatorname{Range}(P_p)\subset E_p
\end{align*}
and
\begin{align*}
K_p:=\ker(P_p)\subset E_p.
\end{align*}
For every $v\in E_p$,
\begin{align*}
v=P_pv+(v-P_pv).
\end{align*}
Here $P_pv\in I_p$, and
\begin{align*}
P_p(v-P_pv)=P_pv-P_p^2v=P_pv-P_pv=0,
\end{align*}
so $v-P_pv\in K_p$. Thus
\begin{align*}
E_p=I_p+K_p.
\end{align*}
If $z\in I_p\cap K_p$, then $z=P_pu$ for some $u\in E_p$ and also $P_pz=0$. Hence
\begin{align*}
z=P_pu=P_p^2u=P_pz=0.
\end{align*}
Therefore
\begin{align*}
E_p=I_p\oplus K_p.
\end{align*}
Now let $x\in I_p$ and $y\in K_p$. Choose $u\in E_p$ such that $x=P_pu$. By self-adjointness,
\begin{align*}
g_p(x,y)=g_p(P_pu,y)=g_p(u,P_py)=g_p(u,0)=0.
\end{align*}
Hence $I_p\perp K_p$.
[guided]
The idempotent identity $P_p^2=P_p$ tells us that $P_p$ behaves like a projection algebraically, even before we know what subbundle it projects onto. The natural candidate for the target is its image, so define
\begin{align*}
I_p:=\operatorname{Range}(P_p)\subset E_p,
\end{align*}
and the natural candidate for the complementary direction is its kernel,
\begin{align*}
K_p:=\ker(P_p)\subset E_p.
\end{align*}
We first prove that these two subspaces give a direct-sum decomposition of $E_p$. For any $v\in E_p$, split $v$ as
\begin{align*}
v=P_pv+(v-P_pv).
\end{align*}
The first term $P_pv$ lies in $I_p$ by definition. The second term lies in $K_p$ because idempotence gives
\begin{align*}
P_p(v-P_pv)=P_pv-P_p^2v=P_pv-P_pv=0.
\end{align*}
Thus every vector in $E_p$ is a sum of one vector from $I_p$ and one vector from $K_p$.
We still need uniqueness of the decomposition. Suppose $z\in I_p\cap K_p$. Since $z\in I_p$, there exists $u\in E_p$ such that $z=P_pu$. Since $z\in K_p$, we also have $P_pz=0$. Applying idempotence,
\begin{align*}
z=P_pu=P_p^2u=P_pz=0.
\end{align*}
Therefore $I_p\cap K_p=\{0\}$, and hence
\begin{align*}
E_p=I_p\oplus K_p.
\end{align*}
The self-adjointness condition now upgrades this algebraic direct sum to an orthogonal direct sum. Let $x\in I_p$ and $y\in K_p$. Since $x\in I_p$, choose $u\in E_p$ with $x=P_pu$. Since $y\in K_p$, we have $P_py=0$. Therefore self-adjointness gives
\begin{align*}
g_p(x,y)=g_p(P_pu,y)=g_p(u,P_py)=g_p(u,0)=0.
\end{align*}
So every vector in $I_p$ is orthogonal to every vector in $K_p$, meaning $I_p\perp K_p$.
[/guided]
[/step]
[step:Show that the fibrewise image has locally constant rank]
Define the integer-valued function
\begin{align*}
r:M\to \mathbb{N}\cup\{0\}
\end{align*}
by
\begin{align*}
r(p):=\dim \operatorname{Range}(P_p).
\end{align*}
We prove that $r$ is locally constant.
Fix $p_0\in M$. Choose an open neighbourhood $U\subset M$ of $p_0$ over which $E$ admits a smooth local frame $(e_1,\dots,e_n)$, where $n$ is the rank of $E$. In this frame, $P$ is represented by a smooth matrix-valued map
\begin{align*}
A:U\to \mathbb{R}^{n\times n}
\end{align*}
defined by the relation
\begin{align*}
P_q e_j(q)=\sum_{i=1}^n A_{ij}(q)e_i(q)
\end{align*}
for $q\in U$ and $j\in\{1,\dots,n\}$. Since $P_q^2=P_q$, the representing matrix satisfies
\begin{align*}
A(q)^2=A(q)
\end{align*}
for every $q\in U$.
For a real idempotent matrix, the rank equals the trace. Indeed, the [linear map](/page/Linear%20Map) represented by $A(q)$ has [minimal polynomial](/page/Minimal%20Polynomial) dividing $t(t-1)$, so its only eigenvalues are $0$ and $1$, and its trace is the number of eigenvalues equal to $1$, counted with algebraic multiplicity, which equals its rank. Hence
\begin{align*}
r(q)=\operatorname{tr}(A(q))
\end{align*}
for every $q\in U$.
The function $q\mapsto \operatorname{tr}(A(q))$ is smooth, hence continuous, and its values lie in the discrete subset $\mathbb{N}\cup\{0\}$ of $\mathbb{R}$. Therefore it is constant on a sufficiently small connected neighbourhood of $p_0$. Since $p_0$ was arbitrary, $r$ is locally constant on $M$.
[/step]
[step:Construct a smooth local frame for $P(E)$]
Define the subset $F\subset E$ fibrewise by
\begin{align*}
F_p:=\operatorname{Range}(P_p)
\end{align*}
for each $p\in M$. We show that $F$ is a smooth subbundle of $E$.
Fix $p_0\in M$, and shrink the local trivialising neighbourhood $U\subset M$ from the previous step so that the rank
\begin{align*}
r:=\dim F_q
\end{align*}
is constant for all $q\in U$. If $r=0$, then $F|_U$ is the zero subbundle, so it is smooth over $U$.
Assume $r>0$. With respect to the smooth local frame $(e_1,\dots,e_n)$ of $E|_U$, define smooth local sections
\begin{align*}
s_j:U\to E|_U
\end{align*}
by
\begin{align*}
s_j(q):=P_q e_j(q)
\end{align*}
for $q\in U$ and $j\in\{1,\dots,n\}$. For every $q\in U$, the vectors $s_1(q),\dots,s_n(q)$ span $F_q$ by definition of $F_q=\operatorname{Range}(P_q)$.
Choose indices $j_1,\dots,j_r\in\{1,\dots,n\}$ such that
\begin{align*}
s_{j_1}(p_0),\dots,s_{j_r}(p_0)
\end{align*}
form a basis of $F_{p_0}$. Since [linear independence](/page/Linear%20Independence) is an open condition, after shrinking $U$ around $p_0$ if necessary, the vectors
\begin{align*}
s_{j_1}(q),\dots,s_{j_r}(q)
\end{align*}
remain linearly independent for every $q\in U$. Because $\dim F_q=r$ and these $r$ vectors lie in $F_q$, they form a basis of $F_q$ for every $q\in U$. Thus the sections $s_{j_1},\dots,s_{j_r}$ form a smooth local frame for $F|_U$.
Since every point of $M$ has such a neighbourhood $U$, the fibrewise image $F=P(E)$ is a smooth subbundle of $E$.
[/step]
[step:Identify $P$ as the orthogonal projection onto $F$]
It remains to prove that $P$ is the fibrewise $g$-orthogonal projection onto the smooth subbundle $F=P(E)$.
Fix $p\in M$. From the fibrewise decomposition above,
\begin{align*}
E_p=F_p\oplus \ker(P_p)
\end{align*}
and
\begin{align*}
F_p\perp \ker(P_p).
\end{align*}
Therefore
\begin{align*}
\ker(P_p)\subset F_p^\perp.
\end{align*}
Conversely, let $z\in F_p^\perp$. Since $P_pz\in F_p$, self-adjointness and idempotence give
\begin{align*}
g_p(P_pz,P_pz)=g_p(z,P_p^2z)=g_p(z,P_pz)=0.
\end{align*}
The fibre metric $g_p$ is positive definite, so $P_pz=0$, and hence $z\in\ker(P_p)$. Thus
\begin{align*}
\ker(P_p)=F_p^\perp.
\end{align*}
For every $v\in E_p$, the decomposition
\begin{align*}
v=P_pv+(v-P_pv)
\end{align*}
has $P_pv\in F_p$ and $v-P_pv\in F_p^\perp$. Hence $P_pv$ is exactly the $F_p$ component of $v$ in the [orthogonal decomposition](/theorems/436)
\begin{align*}
E_p=F_p\oplus F_p^\perp.
\end{align*}
Therefore $P_p$ is the $g_p$-orthogonal projection of $E_p$ onto $F_p$.
Since this holds for every $p\in M$, the smooth bundle endomorphism $P:E\to E$ is the fibrewise $g$-orthogonal projection onto the smooth subbundle $F=P(E)$. This proves the converse implication and completes the proof.
[/step]