I'll show that if $f$ is one to one and not monotone in $[a,b]$ then there exist $x_1,x_2,x_3\in[a,b]$ such that $x_1<x_2<x_3$ and $f(x_2)<f(x_1),f(x_3)$ or $f(x_1),f(x_3)<f(x_2)$:
(Note: I tried to write the proof similiar to nested if statements in computer programming for better flow)
Since $f$ is one to one we get that $f(a)\neq f(b)$ and hence there are two cases $f(a)<f(b)$ or $f(a)>f(b)$
if $f(a)<f(b)$ then:
Since $f$ is not monotone, we get that in particualr $f$ is not decreasing and so there exists $u,v\in[a,b]$ such that $f(u)>f(v)$ (because $f$ is one to one, there cannot be equalty).
Now there two cases $u=a$ or $u\neq a$:
if $u=a$ then:
Since $u<v$ we get that $a<v$ and that $f(a)>f(v)$
Now we'll prove that $v\neq b$:
If $v = b$ we get that $f(a)>f(b)$ which contradicts the fact that $f(a)<f(b)$, And so $v\neq b$ and hence we get that $v\in(a,b)$.
Now since $f(a)>f(v)$ and since $f(b)>f(a)$ we get that $f(v)<f(a),f(b)$.
Now set $x_1 = a, x_2 = v, x_3=b$ and we get that $x_1<x_2<x_3$ and that $f(x_2)<f(x_1),f(x_3)$.
if $u\neq a$ then:
Now we'll show that $u\neq b$ because if $u = b$ we get that $b=u<v$ and so $v\notin [a,b]$ which is a contradiction and so $u\in(a,b)$.
Now there are two cases: $v=b$ or $v\neq b$
if $v=b$ then:
We get that $f(u)>f(b)$ and since $f(b)>f(a)$ we get that $f(a),f(b)<f(u)$
and since $u\in(a,b)$ we get that $a<u<b$.
Now set $x_1 = a, x_2 = u, x_3=b$ and we get that $x_1<x_2<x_3$ and that $f(x_1),f(x_3)<f(x_2)$.
if $v\neq b$ then:
We'll show that $v\in(a,b)$:
Since $v\in[a,b]$ we get that $v\leq b$ but since $v\neq b$ we got that $v<b$. Now since $a<u<v$ we get that that $a<u$ and so $v\in(a,b)$.
and we got $a<u<v<b$.
Now there are two cases: $f(a)<f(u)$ or $f(b)>f(v)$
Because if $f(a)>f(u)$ and $f(b)<f(v)$ and since $f(u)>f(v)$ we get that $f(a)>f(u)>f(v)>f(b)$ and so $f(a)>f(b)$ which is a contradiction.
if $f(a)<f(u)$ then:
Take $x_1=a,x_2=u,x_3=v$ and we get that $x_1<x_2<x_3$ and since $f(u)>f(a),f(v)$ we get $f(x_1),f(x_3)<f(x_2)$.
if $f(b)>f(v)$ then:
Take $x_1 = u, x_2=v,x_3=b$ and we get that $x_1<x_2<x_3$ and since $f(b),f(u)>f(v)$ we get $f(x_2)<f(x_1),f(x_3)$.
Similarly we prove for the case $f(a)>f(b)$.