This is a known problem. But the condition that is missing in the problem statement given here, is that f(x) is non-negative.
You will need the following result:
Schwarz Bunyakovsky Inequality -
\left( \int_0^a f(x) g(x) dx \right)^2 \le \int_0^a f^2(x) dx \int_0^a g^2 (x) dx
I will give an easy proof here that I read in an interesting book 'Cauchy Schwarz Master Class' [this inequality resembles the Cauchy Schwarz Inequality]
Proof:
For some real t, we have \int_0^a (tf(x)- g(x))^2 dx \ge 0
Now,
\int_0^a (tf(x)- g(x))^2 dx = \int_0^a f^2(x) dx t^2 - 2t \int_0^a f(x) dx \int_0^a g(x) dx + \int_0^a g^2(x) dx
which is obviously a quadratic in t. For this to assume non-negative
values we must have D \le 0 where D = 4 \left[\left( \int_0^a f(x) dx \int_0^a g(x) dx \right)^2 - \int_0^a f^2(x) dx \int_0^a g^2(x) dx \right] and you can see that the given inequality immediately follows.
Its important to note when equality holds. Its when f(x) = t g(x) for x \in [0,a]
Now, to the problem itself.
We have \left( \int_0^a x f(x) dx \right)^2 \le \int_0^a \left(\sqrt{f(x)} \right)^2 dx \int_0^a \left(x \sqrt{f(x)} \right)^2 dx
But from the given conditions we see that equality holds here.
This is possible iff \sqrt{f(x)} = \lambda x \sqrt{f(x)} which is absurd as f cannot be identically zero from the 1st integral.
Hence no such functions exist