$f(A \cap B)\subset f(A)\cap f(B)$, and otherwise? I got a serious doubt ahead the question

Be $f:X\longrightarrow Y$ a function. If $A,B\subset X$, show that $f(A \cap  B)\subset f(A)\cap f(B)$

I did as follows
$$\forall\;y\in f(A\cap B)\Longrightarrow \exists x\in A\cap B, \text{ such that } f(x)=y\\ \Longrightarrow x \in A\text{ and }x\in B\Longrightarrow f(x)\in f(A)\text{ and }f(x)\in f(B)\\ \Longrightarrow f(x)\in f(A)\cap f(B)\Longrightarrow y\in f(A)\cap f(B)$$
This ensures that $\forall y \in f(A\cap B)$ then $y\in f(A)\cap f(B)$, therefore $f(A\cap B)\subset f(A)\cap f(B)$.
Okay, we have the full demonstration.
We know that for equality to be valid, then $ f $ must be injective. But my question is when should I see that equality is not worth, not by counter example, but finding an error in the following demonstration
$$\forall\;y\in f(A)\cap f(B)\Longrightarrow y\in f(A)\text{ and }y\in f(B) \Longrightarrow \\ \exists x\in A \text{ and } B, \text{ such that } f(x)=y\\ \Longrightarrow x \in A\cap B\ \Longrightarrow f(x)\in f(A\cap B)\Longrightarrow y\in f(A\cap B)$$
Where is the error in the statement? Which of these steps can not do and why?
 A: you wrote :
$$\forall\;y\in f(A)\cap f(B)\Longrightarrow y\in f(A)\text{ and }y\in f(B) \Longrightarrow \\ \exists x\in A \text{ and } B, \text{ such that } f(x)=y\\ $$
The problem is in the last implication : from $y\in f(A)\text{ and }y\in f(B)$ you get that there exist $x_A\in A$ and $x_B\in B$ such that $f(x_A)=y=f(x_B)$, you cannot assume that $x_A=x=x_B$.
A: Suppose $y\in f(A)\cap f(B)$. Then $y\in f(A)$, so there is $x_1\in A$ with $f(x)=y$. Moreover $y\in f(B)$, so there is $x_2\in B$ such that $f(x_2)=y$.
There's no reason why we should have $x_1=x_2$, except in the case when $f$ is injective.
Counterexample: $X=\{1,2\}$, $Y=\{0\}$, $f(1)=f(2)=0$. With $A=\{1\}$ and $B=\{2\}$ we have
$$
f(A\cap B)=f(\emptyset)=\emptyset\\
f(A)\cap f(B)=\{0\}\cap\{0\}=\{0\}
$$
If you had written the proof in words, instead of piling up symbols, you'd probably have discovered the issue.
Of course we might take $x_1=x_2$ in special cases. even when $f$ is not injective. For particuler subsets $A$ and $B$ we could have $f(A\cap B)=f(A)\cap f(B)$ (for example, when $B=X$), but not in general, unless $f$ is injective.
Actually, it's easy to prove that $f$ is injective if and only if, for all $A,B\subset X$, $f(A\cap B)=f(A)\cap f(B)$.
A: $\forall\;y\in f(A)\cap f(B)\Longrightarrow y\in f(A)\text{ and }y\in f(B) \Longrightarrow  \exists x\in A \text{ and } B, \text{ such that } f(x)=y$
You have problem here. $y\in f(A)\text{ and }y\in f(B) \Longrightarrow \exists x_1\in A \text{ and } x_2 \in B, \text{ such that } f(x_1)=y=f(x_2).$ These $x_1$ and $x_2$ need not be equal. There you need the injectivity of $f$ to conclude that $x_1=x_2.$
A: True, if $y\in f(A)\cap f(B),$ then (1) there exists $x\in A$ such that $f(x)=y,$ and (2) there exists $x\in B$ such that $f(x)=y.$ The error is in assuming that these are referring to a particular $x$ and that the $x$ is the same in both cases!
Rather, we should interpret (1) as telling us that $\{x\in A:f(x)=y\}\neq\emptyset,$ and interpret (2) similarly. However, without injectivity, we can't necessarily conclude that $$\{x\in A:f(x)=y\}\cap\{x\in B:f(x)=y\}\neq\emptyset,$$ which is equivalent to saying that there is some $x\in A\cap B$ such that $f(x)=y.$
