Proof that $f(x)=0 \forall x \in [a,b]$ Lemma:
If $f \in C([a,b])$ and $\int_a^b f(x) h(x) dx=0 \  \forall h \in C^2([a,b])$ with $h(a)=h(b)=0$ then $f(x)=0 \ \forall x \in [a,b]$.
Proof of lemma:
Suppose that there is a $x_0 \in (a,b)$ such that $f(x_0) \neq 0$, for example without loss of generality we suppose that $f(x_0)>0$.
Because of continuity there is an interval $[x_1, x_2] \subset (a,b)$ such that $x_0 \in (x_1, x_2)$ and $f(x)>0 \ \forall x \in (x_1, x_2)$.
We define the function $g(x)=\left\{\begin{matrix}
(x_2-x)^3 (x-x_1)^3 & , x \in (x_1, x_2)\\ \\
0 & ,  x \in [a,b] \setminus{(x_1,x_2)} 
\end{matrix}\right.$.
Then $g \in C^2([a,b])$ and $g(a)=g(b)=0$. From the hypothesis we have:
$$\int_a^b f(x)g(x) dx=0$$
But $\int_a^b f(x)g(x) dx= \int_{x_1}^{x_2} f(x)g(x) dx>0$, contradiction.
First of all, why do we say that there is an interval $[x_1, x_2] \subset (a,b)$ such that $x_0 \in (x_1, x_2)$ and $f(x)>0 \forall x \in (x_1, x_2)$? Why don't we pick the closed interval $[x_1, x_2]$ ? 
Also why does it hold that $\int_a^b f(x) g(x) dx= \int_{x_1}^{x_2} f(x) g(x) dx$?
Furthermore, the prof told us that we couldn't take the function
$g(x)=\left\{\begin{matrix}
(x_2-x)^2 (x-x_1)^2 & , x \in (x_1, x_2)\\ \\
0 & ,  x \in [a,b] \setminus{(x_1,x_2)} 
\end{matrix}\right.$
but the powers both of $(x_2-x), (x-x_1)$ have to be greater or equal to $3$. Why is it like that?

Short answer:


*

*Just a mater of taste. 

*Because $g(x)$, and therefore $f(x)g(x)$, is zero outside $(x_1,x_2)$.

*Because the function must be twice continuously differentiable.

