Let $X$ be a metric space such that for every metric space $Y$ and any continuous function $f : X \to Y$ , $f(X)$ is closed in $Y$ , then is $X$ compact ?
Compare with this $A \subseteq \mathbb R^n $ s.t. for every continuous function $f : A \to \mathbb R$ , $f(A)$ is closed in $\mathbb R$ , is $A$ closed $\mathbb R^n$?
Any real-valued function $f$ on $X$ is bounded since the image $\tilde{f}\colon X \xrightarrow{f} \Bbb{R} \xrightarrow{\cong} (0,1) \hookrightarrow \Bbb{R}$ is closed.
Using this you can go to the question: If every real-valued continuous function is bounded on $X$ (metric space), then $X$ is compact.
Edit: A metric space $X$ is compact if and only if it is complete and totally bounded.
There is a inclusion of $X$ into one of its completions and the image of $X$ is dense. By the assumption the image of $X$ is closed we know that $X$ is complete.
Assume $X$ is not totally bounded. So there is an $\varepsilon > 0$, such that we can not cover $X$ by a finite number of balls with radius $2\varepsilon$. Now we construct pairwise disjoint open balls $B_i= B_{\varepsilon_i}(x_i)$ with $i \in \Bbb{N}$. Let $x_0$ be any point in $X$ and $\varepsilon_0 = \varepsilon$. Now assume we have given $(x_i, \varepsilon_i )$ for $0\le i \le n$ such that the $B_i$ are pairwise disjoint. Then $\overline{\bigcup_{i=0}^n B_i} \subset \bigcup_{i=0}^n B_{2\varepsilon}(x_i) \subsetneq X $. So we find $(x_{n+1} , \varepsilon_{n+1})$ such that $B_i$ are paarwise disjoint for $0\le i \le n+1$.
By Urysohn's lemma we find functions $f_i$ with $f_i(x_i)=i$ and $f_i(x)=0$ for $x \notin B_{1/2 \cdot \varepsilon_i} (x_i)$. For any $x\in X$ there exists a neighborhood of $X$ such that only finitely many $f_i$ are nonzero. Thus $f = \sum f_i$ is a well defined unbounded function on $X$. This is a contradiction to the fact that any function on $X$ is bounded. Thus $X$ is totally bounded.