I shall consider only the case that $f$ is lower semi-continuous, and interpret the question pertaining to this case as follows.
Let $(X,\tau)$ be a compact topological space, and let $f:X\to \mathbb{R}$ be lower semi-continuous ($f$'s range is assumed to be equipped with the Euclidean topology). Which of the following assertions holds for sure?
$f$ is bounded.
$f$ attains a minimum and a maximum.
If $x^*$ is the limit of some minimizing sequence or of some maximizing sequence, then $f$ attains an extremum at $x^*$.
Answer
None of the assertions holds for sure.
As a counter-example, set $X := [0,1]$, define $\tau$ to be the topology induced on $[0,1]$ by the Euclidean norm, and consider the function $f:X\rightarrow\mathbb{R}$, defined as follows. For every $x \in X$,
$$
f(x) := \begin{cases}
\frac{1}{x}, & x \in (0,1], \\
2, & x = 0.
\end{cases}
$$
Then $(X,\tau)$ is a compact topological space, and $f$ is lower semi-continuous, but
$f$ is not bounded,
$f$ does not attain a maximum, and
the harmonic sequence $h = (h_1, h_2, \dots)$, $h_n := \frac{1}{n}$, is maximizing, since $\lim_{n\rightarrow\infty} f(h_n) = \infty = \sup\ f(X)$, however $f$ does not attain an extremum at $\lim_{n\rightarrow\infty} h_n = 0$, as $\underset{=1}{f(1)} < \underset{=2}{f(0)} < \underset{=3}{f(1/3)}$.