The easiest argument I know (which works for path-metrics on topological manifolds $X$ and in even greater generality) is to consider the induced map $f^2: X^2\to Y^2$. This map also preserves the product measure. Set $$ \Delta_r(X)=\{(x,y)\in X^2: d(x,y)\le r\}. $$ By the assumption, $f^2(\Delta_r(X))\subset \Delta_r(Y)$. If $f$ is not an isometry, there exists $r>0$ such that $f^2(\Delta_r)$ is a proper subset of $\Delta_r$, hence, by compactness, the interior of the complement $$ \Delta_r(Y) \setminus f^2(\Delta_r(X)) $$ is nonempty, hence, has positive measure. (This is the only place where I am using the manifold assumption.) A contradiction.