Suppose that $g$ attains a local maximum at $a$. Then $\lim_{x \to a+} \frac{g(x)-g(a)}{x-a} \leq 0.$ Analogously, if $g$ attains a local maximum at $b$, then $\lim_{x \to b-} \frac{g(x)-g(b)}{x-b}\geq 0.$ But both contradict $g'(a)>0$ and $g'(b)<0$. Hence the maximum, which exists since $g$ is continuous on $[a,b]$, must lie inside $[a,b]$.
Actually, you can visualize the setting: $g'(a)>0$ means that $g$ leaves $a$ in an increasing way, and then reaches $b$ in a decreasing way. Therefore $g$ must attain a maximum somewhere between $a$ and $b$.