Let's assume WLOG that $f(0) = 0$. For every $r$, it follows that $f$ defines an isometry from the sphere of radius $r$ to the sphere of radius $r$.
Proposition: Any isometry $f : X \to X$ of a compact metric space is bijective.
Proof. $f$ is clearly injective. Suppose $f$ is not bijective. Then $f(X)$ is compact, so given $x \in X \setminus f(X)$ the distance $\text{dist}(x, f(X))$ is positive. Pick $\epsilon < \text{dist}(x, f(X))$. Let $N$ be the smallest positive integer for which $X$ admits a cover by $N$ open sets of diameter less than $\epsilon$. No such set containing $x$ can intersect $f(X)$, but by pulling back along $f$ it follows that we can find a cover of $X$ by $N-1$ open sets of diameter less than $\epsilon$; contradiction.
(In fact any isometry of a compact metric space is a homeomorphism, since a continuous bijection from a compact space to a Hausdorff space is necessarily closed.)
Apparently there are counterexamples to the above when $X$ is not compact, but I don't know any nice ones off the top of my head.