Let $M$ be a metric space and let $T:M\rightarrow M$ be a distance-preserving map. $T$ is obviously injective. Under some circumstances, it is also necessarily surjective (examples below). I am wondering if there is a good general characterization (in terms of $M$) of when this is the case.
Under what general conditions on $M$ is $T$ necessarily surjective?
Ideally, I would like a general guideline that can be used to settle the question for "naturally-occurring" classes of $M$, but I don't feel confident this exists, so as a baseline I would like to know (1) if $M$ a compact metric space does it imply $T$ surjective? and (2) if $M$ is a connected Riemannian manifold without boundary does that imply $T$ is surjective?
Some examples of when $T$ is necessarily surjective:
$M$ is a Euclidean space of (finite) dimension $n$. In this case, any isometry $T$ is an element of $O(n)$ composed with a translation. As both translations and orthogonal linear transformations are surjective, so is $T$.
$M$ is a compact Riemannian manifold. Then $M$ has finite volume, and $T$ preserves the volume, so $M\setminus T(M)$ has zero volume. Meanwhile $T(M)$ is compact since $M$ is, and thus closed (since $M$ is hausdorff), so $M\setminus T(M)$ is open, and the only open subset of $M$ with zero volume is the empty set. Thus $T$ is surjective.
[These examples are both essentially about finiteness conditions on $M$ that bring injectivity and surjectivity into coincidence. In the first case, isometries are linear up to a translation, and linear self-maps of finite-dimensional vector spaces are surjective iff they're injective. In the second case, the finiteness condition is compactness.]
Examples when $T$ isn't surjective:
Let $M = \ell^2(\mathbb{R})$, the square-summable sequences of real numbers, which is a Hilbert space. The right-shift operator $(a_1,a_2,\dots)\mapsto (0,a_1,\dots)$ is an isometry but is not surjective.
With a similar idea (but not requiring an infinite-dimensional space), let $M$ be the disjoint union of an $\mathbb{N}$-indexed family of isometrically isomorphic subspaces $M_1,M_2,\dots$. Then let $T$ map $M_1$ isometrically to $M_2$, $M_2$ to $M_3$, etc. Then the image does not contain $M_1$. This shows that $M$ can be a manifold.
Another similar idea: let $M$ be upper half-space $\mathbb{R}^n\times \mathbb{R}_{\geq 0}$, and let $T$ map $(a_1,\dots,a_{n+1})$ to $(a_1,\dots,a_n,a_{n+1}+1)$. This shows that $M$ can be a connected manifold with boundary.