I have two similar exercises of Linear algebra done right, third edition of Axler
Exercise 1: suppose that $V$ is finite-dimensional and $P\in\mathcal L(V)$ such that $P^2=P$ and $\ker(P)\subseteq P(V)^\bot$. Prove that exists some subspace $U$ of $V$ such that $P$ is an orthogonal projection of $V$ on $U$.
Exercise 2: suppose that $V$ is finite-dimensional and $P\in\mathcal L(V)$ such that $P^2=P$ and $\|Pv\|\le\|v\|$ for all $v\in V$. Prove that exists some subspace $U$ of $V$ such that $P$ is an orthogonal projection of $V$ on $U$.
*Note: $V$ is also an inner product space.
I have done a fake proof for both exercises, that is below, but Im unable to see where is the mistake. Can someone enlighten me?
Step 1: let a basis of $\ker(P)$ defined by $z_1,z_2,\ldots,z_m$ that we extend to a basis of $V$ defined by $z_1,z_2,\ldots,z_m,v_1,v_2,\ldots,v_n$. The existence of this basis is ensured because $V$ is a finite-dimensional vector space.
If we apply the Gram-Schmidt procedure to the above basis we have an orthonormal basis $h_1,h_2,\ldots,h_m,u_1,u_2,\ldots,u_n$ with the property that
$$\ker(P)=\operatorname{span}(z_1,z_2,\ldots,z_m)=\operatorname{span}(h_1,h_2,\ldots, h_m)$$
Step 2: if we define $U:=\operatorname{span}(u_1,u_2,\ldots,u_n)$ then by definition $\ker(P)=U^\bot$ and $V=\ker(P)\oplus U$.
Then any $v\in V$ can be defined by $v=u+h$, where $h\in\ker(P)$ and $u\in U$. Hence $P(V)=P(U)$.
Step 3: observe that $P|_U\in\mathcal L(U,P(U))$ is injective, and because $V$ is finite-dimensional $P|_U$ is invertible. Then, because the functional equation $P|_U^2=P|_U$ holds by assumption, we found that
$$P|_U^2 u=P|_U u\implies P|_U^{-1}P|_U^2u=P^{-1}|_UP|_Uu\implies Pu=u,\quad u\in U$$
Hence $P|_U=I$, thus $P(U)=U$, what imply $U=P(V)$.
Step 4: then for any $v\in V$ there is some $u\in P(V)$ and some $h\in \ker(P)=P(V)^\bot$ such that $v=u+h$, and
$$Pv=P(u+h)=Pu+0=u$$
So $P$ is the orthogonal projection of $V$ on $P(V)$.$\Box$
In step 3, you write $P\lvert_U^2 = P\lvert_U$. But $P\lvert_U \in \mathcal{L}(U,P(U))$, so $P\lvert_U^2$ is only defined if $P(U) \subset U$. At that point, you haven't given an argument for that. Once you have done that, you can conclude $P(u) = u$ for all $u\in U$, and that $P$ is the orthogonal projection onto $U$.
However, I would suggest a different style of argument. The condition $P^2 = P$ alone gives a decomposition
$$V = P(V) \oplus \ker P,$$
and $P\lvert_{P(V)} = \operatorname{id}_{P(V)}$. For we can write
$$v = P(v) + \bigl(v - P(v)\bigr)$$
where obviously $P(v) \in P(V)$, and $v - P(v) \in \ker P$ follows from $P^2 = P$.
So $P$ is the projection onto $P(V)$ along $\ker P$. What remains is to see that under the conditions of each exercise, $P$ is an orthogonal projection. And that just means $P(V) \perp \ker P$ (I don't know how Axler defines an orthogonal projection, this may be the definition, or one may need to show that this is an equivalent characterisation of orthogonal projections). In exercise 1, this is immediate. For exercise 2, I suggest an indirect proof. If the projection $P$ is not an orthogonal projection, there is a $v\in V$ with $\lVert P(v)\rVert > \lVert v\rVert$, hence $\lVert P\rVert > 1$. Pick a $v_0 \in P(V) \setminus (\ker P)^{\perp}$ and look for a $v_1 \in \ker P$ such that $\lVert v_0 + v_1\rVert < \lVert v_0\rVert$.