In his book "Analysis I", Terence provides the proof of extremum principle, saying that each function with bounded domain must obtain maxima/minima. In previuos theorem it is already shown that each continuous function with bounded domain is bounded.
$\textbf{Proposition 9.6.7}$ Let $a,b \in \mathbb{R}: a<b$; $X \subset \mathbb{R}$ and let $f: X \to \mathbb{R}$, f is continuous. Then $f$ must obtain maxima/minima at some point $x_{max} / x_{min} \in [a,b]$
In the proof he provides a set $E = \{ f(x): x \in [a,b]\}$ and says maxima is attained with the value of $\sup(E)$ since $\forall x \in [a,b]: x \leq \sup(E)$, which is pretty clear to me.
What I cann not understand is that he says that further, it is necessary to find some $x_{max}$ which satisfies $f(x_{max}) = \sup(E)$. Does its existence not follow naturally from the definition of the set $E$?
No, not really. Imagine you would deviate from your $E$ a bit. For example for $f(x)=\frac{1}{x}$ we could write down $$E:=\{\frac{1}{x}:x\in (1,2]\}.$$ Please note, that the intervall in $E$ is not compact anymore. Then $$\sup(E)=1\geq\frac{1}{x}\mbox{ if }x\in(1,2].$$ Now suppose $1\in E$, which would mean there exists an $x_{max}\in (1,2]$ such that $\frac{1}{x_{max}}=1$. Hence $x_{max}=1$, which is a contradiction.
Hence more work is needed, in which you need to use the compactness of $[a,b]$, see Fred's answer.