Let $f:X\to Y$ and $g:Y\to X$ be injections. For $p\in X,$ consider the sequence $$(p,g^{-1}(p), f^{-1}g^{-1}(p), g^{-1}f^{-1}g^{-1}(p),...)$$ which may terminate after finitely many terms (when an inverse fails to exist), or may continue without end.
Let $O$ be the set of $p\in X$ for which the sequence has an odd number of terms. Let $E$ be the set of $p\in X$ for which the sequence has an even number of terms. Let $I$ be the set of $p\in X$ for which the sequence has no end.
Now let $h(p)=f(p)$ if $p\in O,$ and $h(p)=g^{-1}(p)$ if $p\in E \cup I.$
(1A).Clearly if $\{p_1,p_2\}\subset O$ or if $\{p_1,p_2\}\subset E$ then $h(p_1)=h(p_2)\implies p_1=p_2.$
(1B).Suppose $p_1\in O$ while $p_2\in E\cup I.$ Then $$h(p_1)=h(p_2)\implies f(p_1)=g^{-1}(p_2)\implies p_1=f^{-1}g^{-1}(p_2).$$ But if $p_2 \in E\cup I$ and if $ f^{-1}g^{-1}(p_2)$ exists then $f^{-1}g^{-1}(p_2)\in E\cup I,$ so $p_1\in E\cup I, $ a contradiction to $p_1\in O.$
(1C).Therefore $h:X\to Y$ is an injection.
(2A). For $q\in Y,$ if $g(q)\in E\cup I$ then $h(g(q))=g^{-1}g(q)=q.$
(2B).If $g(q)=x\in O,$ then $g^{-1}(x)$ exists and the sequence $(x,g^{-1}(x), ...)$ has an odd number of terms. So $f^{-1}g^{-1}(x)$ exists, and it also belongs to $O.$ So $h(f^{-1}g^{-1}(x))=f(f^{-1}g^{-1}(x))=g^{-1}(x)=g^{-1}(g(q))=q.$
(2C). Therfore $h:X\to Y$ is a surjection.
I think that drawing a heuristic picture, with $X$ and $Y$ as parallel lines, may help you to grasp this.