This is a standard way of proving Poincare inequality on $\Omega\subset \mathbb{R}^n$, but to simplify the argument, I will do it on $[a,b]$. This might look slightly complicated because the proof reduces to something much simpler for function of one variable.
Let $f\in C^1[a,b]$, we have the following fact $$f(x) - f(y) = \int_0^1 f'(tx + (1-t)y)\cdot(x-y)dt.$$ Now define $\overline f = \frac{1}{b-a} \int_a^b f(z) dz$, we see that $$\begin{align} f(x) - \bar f &= \frac{1}{b-a}\int_a^b f(x) - f(y) dy \\ &= \frac{1}{b-a}\int_a^b\int_0^1 f'(tx + (1-t)y)\cdot(x-y)dt dy \end{align}$$ From Jensen's inequality $$\begin{align} \int_a^b |f(x) - \bar f|^2 dx &\leq \frac{1}{b-a}\int_a^b \int_a^b\int_0^1 |f'(tx + (1-t)y)|^2\cdot|x-y|^2dt dy dx\\ &\leq (b-a) \left\{\int_a^b\int_a^b\int_0^1 |f'(tx + (1-t)y)|^2dt dy dx\right\}\\ &= (b-a) \left\{\int_0^1\int_a^b\int_a^b |f'(tx + (1-t)y)|^2 dy dx dt\right\} \end{align}$$
Now here the trick that I do not quite understand intuitively, and it works so nicely. We break up the integral $$\int_0^1\int_a^b \int_a^b \cdots dydxdt = \int_0^\frac{1}{2}\int_a^b \int_a^b \cdots dy dx dt + \int_\frac{1}{2}^1\int_a^b \int_a^b \cdots dxdydt.$$ When $t\in [0,\frac{1}{2})$, we have $$\int_a^b |f'(tx + (1-t)y)|^2 dy = \frac{1}{1-t}\int_{tx + (1-t)a}^{tx + (1-t)b} |f'(z)|^2 dz \leq 2 \int_a^b |f'(z)|^2 dz.$$ Similiarly, when $t\in [\frac{1}{2},1]$ $$\int_a^b |f'(tx + (1-t)y)|^2 dx = \frac{1}{t}\int_{ta + (1-t)y}^{tb + (1-t)y} |f'(z)|^2 dz \leq 2 \int_a^b |f'(z)|^2 dz.$$ And after some simple calculation, we will get $$\int_a^b |f(x) - \bar f|^2 dx \leq (b-a)^2 \int_a^b |f'(z)|^2 dz.$$
My remark: I tried to do some sketch on paper, so when $t\in [0,\frac{1}{2})$, we are closer to $x$ on the line segment $tx + (1-t)y$ and yet we integrate against $dy$, and vice versa. It seems not quite intuitive for me.
Check your sketch! When $t\in[0,\frac12)$, the expression $tx+(1-t)y$ is closer to $y$ than to $x$ (try $t=0$), so the integrand behaves more like $|f'(y)|^2$. When $t\in[\frac12,1]$ the integrand behaves more like $|f'(x)|^2$.