Lemma: Assume $f$ is continuous on $[a,b]$ and $f(a)=0=f(b).$ Then there exists a sequence of polynomials $p_n$ with $p_n(a)=0=p_n(b)$ such that $p_n\to f$ uniformly on $[a,b].$
Proof: By Weierstrass there are polynomials $q_n$ converging uniformly to $f$ on $[a,b].$ Let $l_n$ be the linear function joining $(a,q_n(a)),(b,q_n(b).$ Then $p_n=q_n-l_n$ does the job.
Proof for the given problem: Given $a<a'<b'<b,$ define $g$ this way: on $[a,a']$ $g$ is the line joining $(a,0)$ and $(a',f(a'));$ on $[a',b'],$ $g=f;$ on $[b',b]$ $g$ is the line joining $(b',f(b'))$ and $(b,0).$ Find polynomials $p_n$ converging to $g$ uniformly as in the lemma. Then
$$0= \int_a^bfp_n = \int_a^{a'}fp_n +\int_{a'}^{b'}fp_n + \int_{b'}^b fp_n $$ $$\to \int_a^{a'}fg+\int_{a'}^{b'}f^2+ \int_{b'}^b fg$$
Now let $a'\to a^+, b'\to b^-$ to see $0=\int_{a}^{b}f^2.$ This proves $f\equiv 0.$