[guided]Assume $p\sim q$. This means precisely that there is an operator $v\in\mathcal{L}(H)$ satisfying
\begin{align*}
v^*v=p
\end{align*}
and
\begin{align*}
vv^*=q.
\end{align*}
The goal is to show that $v$ is not merely an operator on $H$, but becomes a unitary map once we restrict its domain to the range of $p$ and its codomain to the range of $q$.
Because $p$ is a projection, it is the [orthogonal projection](/theorems/437) onto $pH$. Thus
\begin{align*}
H=pH\oplus (pH)^\perp.
\end{align*}
First take $y\in (pH)^\perp$. Then $py=0$. Using the Hilbert-space adjoint relation for $v^*v$, we compute
\begin{align*}
\|vy\|_H^2=(vy,vy)_H=(v^*vy,y)_H=(py,y)_H=0.
\end{align*}
Therefore $vy=0$. This proves that $v$ kills the orthogonal complement of $pH$.
Now take $x\in pH$. Since $p$ acts as the identity on its range, $px=x$. Again using $v^*v=p$, we get
\begin{align*}
\|vx\|_H^2=(vx,vx)_H=(v^*vx,x)_H=(px,x)_H=(x,x)_H=\|x\|_H^2.
\end{align*}
So $v$ preserves norms on $pH$. Since $v$ is linear, the polarization identity implies that $v|_{pH}$ preserves the Hilbert-space [inner product](/page/Inner%20Product) on $pH$. Equivalently, $v|_{pH}$ is an isometry from $pH$ into $H$.
It remains to prove that the image is exactly $qH$. First, for any $h\in H$, the decomposition $h=ph+(h-ph)$ has $h-ph\in (pH)^\perp$, and $v$ vanishes on $(pH)^\perp$. Hence $vh=vph$. Therefore
\begin{align*}
q(vh)=vv^*vh=v(v^*v)h=vph=vh.
\end{align*}
This shows that $vh$ is fixed by $q$, so $vh\in qH$. Hence $\operatorname{Range}(v)\subset qH$.
For the reverse inclusion, take $z\in qH$. Then $qz=z$, and using $q=vv^*$ gives
\begin{align*}
z=qz=vv^*z=v(v^*z).
\end{align*}
Thus $z$ lies in the range of $v$. We also need the preimage $v^*z$ to lie in $pH$, because we want the range of the restricted map $v|_{pH}$, not just the range of $v$ on all of $H$. This follows from
\begin{align*}
p(v^*z)=v^*vv^*z=v^*qz=v^*z.
\end{align*}
So $v^*z\in pH$, and $z=v(v^*z)\in v(pH)$.
We have proved
\begin{align*}
v(pH)=qH.
\end{align*}
The restricted map $v|_{pH}:pH\to qH$ is therefore a surjective isometry, hence a unitary isomorphism. Consequently $pH$ and $qH$ have the same Hilbert-space dimension.[/guided]