I saw the following proof here.
Proof:
Let $f(a) = f(b)$.
Then $g(f(a)) = g(f(b)) \implies g\circ f(a) = g \circ f(b)$
But we know that $g \circ f$ is injective. Hence, $a = b$
We have shown that if $f(a) = f(b)$ then $ a = b \implies $ $f(x)$ is injective.
In this when we show that $g(f(a)) = g(f(b))$, doesn't it mean that $g(x$) is also injective. If not, why?
Take a look at $f(x)= e^x$ and $g(x)= |x|$ (both from $\mathbb{R}\to \mathbb{R}$). Since $e^x>0$ for all $x$ we have $$g(f(x))=|e^x| =e^x$$
so $g\circ f$ is injective, but $g$ is not.