If $f:A\to B$ and $g :B\to C$ are 2 mappings then if $g\circ f:A\to C$ is injective then prove that $f$ is injective My attempt :
Let $f(x_1)=f(x_2)$ for some $x_1$ and $x_2$.
$g\circ f(x_1)=g\circ f(x_2)$ implies that $x_1=x_2$ holds. 
Thus $f(x_1)=f(x_2)$ implies that $x_1=x_2$ and therefore $f$ is injective
What I am not able to understand is that is it necessary for $g$ to be injective? Can someone explain it with mapping diagrams instead of giving examples?
 A: Here you go:

The red lines are to illustrate the necessity of $f$ being injective. Note that, as soon as $f$ sends two points in $A$ to the same point in $B$, there's no separating them out again once $g$ maps them to $C$. So, as the result claims, $f$ must definitely be injective.
The blue lines are to illustrate why $g$ may not be injective. We can have $g$ send points outside of $f(A)$ to wherever we want (including to points that would break injectivity), so long as $g$ remains injective when restricted to $f(A)$.
A: Let there be $x_1 , x_2 $. Let's assume $f(x_1)=f(x_2) $. We know that $\forall x_1, x_2. (g\circ f(x_1) =g \circ f(x_2) \rightarrow x_1=x_2). $ But we know that $f(x_1)=f(x_2)$, so let's just insert both sides of the equation to g, and we get $g \circ f(x_1)= g \circ f(x_2) $. By Modus Ponens we get that $x_1=x_2$. That is the full proof.
Regarding your question - $g$ does not have to be injective for there could be some element in the Domain of $g$ that $f$ does not map any of the elements of his domain to. For example, let's look at:
$A=\{1,2,3\}, B=\{1,2,3,4\} $
$f\in A \rightarrow B, f(x)=x$
$g \in B \rightarrow A, $
$g(x)=\begin{cases} x & x \in \{1,2,3\} \\ 3 & x=4\end{cases}$
A: 
$g\circ f(x_1)=g\circ f(x_2)$ implies that $x_1=x_2$ holds

Yes, but why?

What I am not able to understand is that is it necessary for g to be injective?

No, that is not necessary. You can see that in your proof. Because your proof does not rely on the fact that $g$ is injective. 
We use that $g\circ f$ is injective.
I do not know what you mean with a 'mapping diagram'. What I associate with that, are these trivial diagrams to help you visualise what is going on in a very simple way. 
But what really helps are counterexamples to see that this property does not have to hold.
A: Injective means that different inputs will produce different outputs, while being a function means that same inputs will produce same outputs. If $f$ is not injective, then there are some different inputs $x,y$ that produce the same output,  i.e. $f(x)=f(y)$. But if this is true, $g(f(x))=g(f(y))$, which contradicts the claim that $g\circ f$ is injective.
