This cannot be proved "naively". Indeed this question is an equivalent formulation of an axiom known as The Axiom of Choice.
The axiom of choice says that given a family of non-empty sets, we can choose one element from each member of the family.
Using the axiom of choice, note that for every $y\in Y$ the set $f^{-1}(y)$ is non-empty. We therefore have a function which chooses one element from each preimage, call it $g$. This function is as wanted, since $g(y)\in f^{-1}(y)$ and therefore $f(g(y))=y$ as wanted, this also implies $g$ is injective because if $y_1\neq y_2$ then $g(y_1)$ and $g(y_2)$ are taken from disjoint sets.