Let $\omega$ be the first infinite ordinal and for all $n\in \omega $ define $n=\{0,1,2,...,n-1\}$. In particular, $2=\{0,1\}$.
Let $f:\omega\rightarrow \omega$, $f(x)=x^2 $.
Now $4=f(2)=f(\{0,1\})=\{n\in \omega:\exists x\in \{0,1\}, f(x)=n\}=\{f(0),f(1)\}=\{0,1\}$.
But $4\neq \{0,1\}$.
You're mixing two meanings of $f(x)$.
This is why in the context of set theory (where everything is a set), the latter is often denoted by $f[x]$ or $f"x$.