[guided]The disjoint union remembers which summand an element came from. We implement this by tags: elements of $A\sqcup B$ are either $(a,0)$ with $a\in A$ or $(b,1)$ with $b\in B$. The natural map sends the $A$-summand through $f$ and the $B$-summand through $g$:
\begin{align*}
F:A\sqcup B&\to A'\sqcup B'\\
(a,0)&\mapsto (f(a),0)\\
(b,1)&\mapsto (g(b),1).
\end{align*}
The tags are essential because they prevent ambiguity between an element coming from $A$ and an element coming from $B$.
To prove that $F$ is bijective, define the candidate inverse by applying the inverse bijections on the corresponding summands:
\begin{align*}
F^{-}:A'\sqcup B'&\to A\sqcup B\\
(a',0)&\mapsto (f^{-1}(a'),0)\\
(b',1)&\mapsto (g^{-1}(b'),1).
\end{align*}
Now compute both composites. For $(a,0)\in A\times\{0\}$,
\begin{align*}
F^{-}(F(a,0))=F^{-}(f(a),0)=(f^{-1}(f(a)),0)=(a,0),
\end{align*}
and for $(b,1)\in B\times\{1\}$,
\begin{align*}
F^{-}(F(b,1))=F^{-}(g(b),1)=(g^{-1}(g(b)),1)=(b,1).
\end{align*}
Therefore $F^{-}\circ F=\operatorname{id}_{A\sqcup B}$. Conversely, for $(a',0)\in A'\times\{0\}$ and $(b',1)\in B'\times\{1\}$,
\begin{align*}
F(F^{-}(a',0))&=F(f^{-1}(a'),0)=(f(f^{-1}(a')),0)=(a',0),\\
F(F^{-}(b',1))&=F(g^{-1}(b'),1)=(g(g^{-1}(b')),1)=(b',1).
\end{align*}
Thus $F\circ F^{-}=\operatorname{id}_{A'\sqcup B'}$. Hence $F$ is a bijection, and the two disjoint unions have the same cardinality.[/guided]