Despite of being aware of the duplicates of this question, I am posting it just to have my approach verified.
Let $f:X \to X$ be an isometry on $X$. By definition, when $f(a)=f(b)$, then $ d_X(f(a),f(b))=0=d(a,b) \implies a=b$, i.e. it is injective.
The set $X$ is compact, hence it is closed and bounded. Suppose, $X-f(X)=Y \neq \emptyset$. Taking $p\in Y$, we take the minimum distance from $f(X)$ to be $\delta$.
We now take an open cover of $X$, in such a manner, that in each $G_{X_i}$, $\displaystyle\sup\{d_X(s,t): s, t \in G_{X_i}\}=\delta$. Now, let $\displaystyle\sup\{d_X(s,t): s, t \in X\}=\lambda$. We need at most $\lceil \frac{\lambda}{\delta} \rceil $ open sets. Again, by isometry, we get corresponding $\sup{d_X(f(s),f(t))}=\delta$. But, by Pigeon Hole Principle, we see that if not surjective, then the function fails to be injective due to overlapping.
I know that this "proof" is very vague and inappropriate, but I need some direction.
Another doubt: How do I prove that $f(X)$ is compact?
Attempt: $X \subset G_1\cup G_2 \cup...\cup G_n \implies f(X) \subset f(G_1) \cup ...\cup f(G_n)$. For an arbitrary $g\in G_k$, $d_X(z,g)<\beta \implies z\in G_k$ for some $\beta >0$. Now, $f(g) \in f(G_k)$ and $d_X(f(z),f(g))<\beta \implies f(z) \in f(G_k)$. We repeat this for every possible open cover.
Does this work?