Here's a trick proof using nothing but the Cauchy-Schwarz inequality. It only works for $p=2$, and it gives a constant $4$ instead of $2$ (regarding which note that Jack says $4$ is optimal and other reliable sources agree), but it's extremely simple:
First note that we can assume $f\ge0$. This will simplify the notation, and also simplify a certain technicality below.
Now note that $$\frac1{x^2}\left(\int_0^xf(t)\,dt\right)^2
=\left(\int_0^1 f(xt)\,dt\right)^2=\int_0^1\int_0^1f(xt)f(xs)\,dtds.$$
(Changing the square of that integral into a double integral is why I call this a "trick" proof. I suspect you could do something similar if $p>2$ is an integer...)
Inserting this above and changing the order of integration you get
$$\int_0^\infty\frac1{x^2}\left(\int_0^xf(t)\,dt\right)^2\,dx
=\int_0^1\int_0^1\int_0^\infty f(xt)f(xs)\,dxdtds.$$
Detail: Someone objected to changing the order of integration without being careful about the hypotheses. Worrying about this is admirable, but in fact here there's no problem, since everything in sight is positive, and Tonelli's theorem says that Fubini is always ok for positive functions.
Now Cauchy-Schwarz shows that
$$\int_0^\infty f(xt)f(xs)\,dx\le\left(\int_0^\infty f(xt)^2\,dt\right)^{1/2}\left(\int_0^\infty f(xs)^2\,dt\right)^{1/2}
=s^{-1/2}t^{-1/2}\int_0^\infty f(x)^2\,dx,$$so
$$\int_0^\infty\frac1{x^2}\left(\int_0^xf(t)\,dt\right)^2\,dx\le\int_0^1\int_0^1s^{-1/2}t^{-1/2}\,dtds\int_0^\infty f(x)^2\,dx=4\int_0^\infty f(x)^2\,dx.$$