I'm trying to understand a certain step within the proof for the mean value theorem, which states that if $f : [a,b] \rightarrow \mathbb{R}$ is differentiable, there exists an $x_0 \in [a,b]$ with $\frac{f(b)-f(a)}{a-b} = f^{\prime}$.
For the proof, we first prove that if a differentiable function $f : [a,b] \rightarrow \mathbb{R}$ has a maximum or minimum in an inner point of $[a,b]$, it's derivative in that point is equal to zero. In order to see that, let's suppose that $x_0 \in [a,b]$ is the x-coordinate for the maximum point, then we have: $\forall x \in [a,b]: f(x)-f(x_0) \leq 0$ and therefore:
for $x<x_0: \frac{f(x)-f(x_0)}{x-x_0} \geq 0$ and also
for $x>x_0: \frac{f(x)-f(x_0)}{x-x_0} \leq 0$.
Because of that, we have:
limit from the left: $lim_{x\nearrow x_0} \frac{f(x)-f(x_0)}{x-x_0} \geq 0$
limit from the right: $lim_{x\searrow x_0} \frac{f(x)-f(x_0)}{x-x_0} \leq 0$
and since we know that for a differentiable function those limits are equal, the derivative in that point will be zero: $lim_{x\rightarrow x_0} \frac{f(x)-f(x_0)}{x-x_0} = 0$ $\square$.
Now, to prove the mean value theorem, we define:
$g(x) = f(x) - secant(x)= f(x) - (f(a) + \frac{f(b)-f(a)}{b-a}(x-a))$, which fulfills:
$g(a) = 0, g(b) = 0$
If $g(x)$ now is constant, $g^{\prime}(x)=0 \Leftrightarrow \frac{f(b)-f(a)}{a-b} = f^{\prime}(x)$ If $g(x)$ is not constant, it has a maximum or minimum in in an inner point of $x_0$ on $[a,b]$, where we have $g^{\prime}(x) = 0 \Leftrightarrow \frac{f(b)-f(a)}{a-b} = f^{\prime}(x) \square$.
Now, I understand the whole proof except for the last two lines, in which I can't get my head wrapped around why if the function that is definded by "function - secant" isn't increasing or decreasing, the derivative in that point must be equal to the secant.
Thanks for anyone reading that super long proof and excuse any inaccuracies in the proof since I tried translating it from my native language. Please point them out. Any tips for my problem are appreciated.

$g$ is a differentiable function on $[a, b]$, so we can use theorem about derivative in max/min been zero.
If $g$ isn't constant, then it has either maximum or minimum (or both) in inner point. Indeed, if $g$ isn't constant, then $g(x) \neq 0$ for some $x$. Wlog we can assume $g(x) > 0$. Now take $y_0 = \sup \{g(x) | x \in [a, b]\}$ - as $y_0 > g(x)$, we have $y_0 > 0$. As $g$ is continuous, for some $x_0$ we have $g(x_0) = y_0$. And as $g(a) = g(b) = 0$, we have $x_0 \neq a$, $x_0 \neq b$, so $x_0$ is an inner point.
From first theorem, $g'(x_0) = 0$. Now substitute expression for $g$: $$g(x) = f(x) - (f(a) + \frac{f(b) - f(a)}{b - a}(x - a))$$ $$g'(x) = f'(x) - \frac{f(b) - f(a)}{b - a}$$ $$0 = g'(x_0) = f'(x_0) - \frac{f(b) - f(a)}{b - a}$$ $$f'(x_0) = \frac{f(b) - f(a)}{b - a}$$
It's a specific case of a bit more general construction: if function $h(x) = f(x) - cx$ has an extremum (and thus zero derivative) in $x_0$, you have $f'(x_0) = c$. You can think about adding $-cx$ to function as rotating it's graph around origin. And if rotated graph has horizontal tangent at some point, then original graph had tangent with angular coefficient $c$ at it.