Let $f: X \rightarrow Y$ and $g: Y \rightarrow X$
If $f \circ g$ is injective and $g$ is surjective - is $f$ injective?
I am trying to learn the way of prooving things. So I'll give it a try and please correct at every wrong step.
I assume that the given statement ist true.
So first I give the condition that $g$ is surjective: $\forall y \in Y : \exists x \in X:g(y)=x$
So two different $y$-values can point to the same $x$-value:
Let $y_1, y_2 \in Y, y_1 \neq y_2 : \exists x \in X : g (y_1)=x $ and $g (y_2)=x$
Next I want to connect the fact that $f \circ g$ is injective with the surjective condition of $g$:
Let $z_1, z_2 \in X \quad$ Because $z_1, z_2 \in X$ it is true that $z_1, z_2 \in g(y)$ thus: $$f \circ g(y_1) = f \circ g (y_2)$$ $$f(z_1) = f(z_2)$$ $$z_1 = z_2$$
So $f$ is injective.
The condition that $g\colon Y\to X$ is surjective translates as $$\forall x\in X\;\exists y\in Y,\;g(y)=x$$ not the way you translated it.
Here are sketches of two proofs:
By contrapositive:
We show that if $f$ is not injective, but $g$ surjective, the $f\circ g$ is not injective.
Indeed, let $y_1, y_2\in Y$ such that $f(y_1)=f(y_2)$. As $g$ is surjective, $y_1$ and $y_2$ have (distinct) preimages by $g$ $x_1,x_2\in X$ This means that $$f(y_1)=f(g(x_1))=f(y_2)=f(g(x_2)),$$ so $f\circ g$ is not injective.
Direct proof:
If $f\circ g$ is injective, it implies $g$ is injective. As it is also surjective by hypothesis, it is bijective. Let $g^{-1}\colon X\to Y$ be the inverse bijection . Then the composition $$(f\circ g)\circ g^{-1}=f\circ( g\circ g^{-1})=f\circ\operatorname{id}_X=f$$ is injective.