For completeness...
There is one variant of the idea of function that doesn't include a notion of codomain. e.g. with this notion, the function defined by $f(x) = x^2$ (where $x$ is a real variable) "remembers" that its domain is all reals and that its image (sometimes called its range) is all nonnegative reals, but doesn't care whether it's being construed as a mapping $\mathbb{R} \to \mathbb{R}_{\geq 0}$, a mapping $\mathbb{R} \to \mathbb{R}$, a mapping $\mathbb{R} \to \mathbb{C}$, or even something more exotic.
For this specific variation on the notion of function, it is true that every injective function is invertible.
I am under the impression that this notion of function was popular once but is no longer popular. However, it still sticks around somewhat due to inertia: e.g. people learned it that way so they taught it to others, related concepts have stuck around, that sort of thing.
For the more modern notion of function, it does "remember" its codomain, and we require the domain of its inverse to be the whole of the codomain, so an injective function is only invertible if it is also bijective.