I know that compact sets imply the existence of a maximizer, but is the converse true:
Let $(X,d)$ be a metric space. Suppose that whenever $f$ is a continuous (and real) function on $X$, there exists a point $y \in X$ such that $f(y) \geq f(x)$ for all $x \in X$. Then X is compact.
If $X$ is metric and not compact, then $X$ has an infinite closed discrete subset $D$. By passing to a subset if necessary, we may assume that $D=\{x_n:n\in\Bbb N\}$ is countably infinite. Now define $f:D\to\Bbb R:x_n\mapsto n$, and apply the Tietze extension theorem to get an unbounded continuous real-valued function on $X$.