I know that for $f\colon X \to Y$, where $e_Y$ is the identity of $Y$:
$$ \ker(f) = \left\{x \in X \, \middle| \, f(x) = e_Y \right\} $$
I've learnt that kernels imply how much a homomorphism fails to be injective. But why is a function non-injective iff $|\ker(f)| > 1$? I can naively think of functions that don't work accordingly.
Most answers answer
$$|\ker(f)| > 1 \Rightarrow \text{f is non-injective}$$ which seems trivial to me, but I'm much more interested in
$$\text{f is non-injective} \Rightarrow |\ker(f)| > 1$$
i.e. why is there no such case, where only one element is mapped to identity, but the other elements have more elements mapped to them. Let's say a group homomorphism $f\colon \mathbb{Q} \to \mathbb{Z}$, both closed under addition, where $\forall x,n \in \mathbb{Z}. f(n) = f(\frac{x}{n}) = n$. It seems to me that $|\ker(f)| = 1$, however $f$ fails to be injective.
If $|\mathrm{Ker}(f)|>1$, then there exists $x, y \in \mathrm{Ker}(f)$ with $x \neq y$. Then $f(x) = e_Y = f(y)$, so $f$ is not injective.
Conversely, since $f$ is a homomorphism, it preserves the algebraic structure from $X$ to $Y$, e.g., if $(X, *_X)$ and $(Y, *_Y)$ are groups, then $f(x *_X y) = f(x) *_Y f(y)$. So if $f$ is not injective, then there exists $x, y \in X$ with $x \neq y$ but $f(x) = f(y)$. Then, $e_Y = f(x) *_Y f(y)^{-1} = f(x) *_Y f(y^{-1}) = f(x *_X y^{-1}) = f(e_X)$. So $e_X, x *_X y^{-1} \in \mathrm{Ker}(f)$ and $e_X \neq x *_X y^{-1}$ by assumption.