Favard's theorem characterizes this in terms of the three-term recurrence. Suppose the polynomials $P_n$ are normalized so that they are monic. Then they are orthogonal polynomials with respect to some Borel measure if and only if there are constants $\alpha_n$ and $\beta_n$ such that $P_n(x) = (x+\alpha_n) P_{n-1}(x) + \beta_n P_{n-2}(x)$ and $\beta_n < 0$. (The sign condition on $\beta_n$ is needed to get a positive measure. I think you still get a signed measure if you have a three-term recurrence with $\beta_n \ge 0$, but I'm not certain offhand.)

This is pretty easy to test for in practice if you are given a sequence of polynomials numerically. Strictly speaking, it doesn't guarantee a weight function as specified in your question, since the measure may not be absolutely continuous with respect to Lebesgue measure, but I assume that's not what you really care about. If it is, then I'm not sure offhand how to characterize that case.