Intuition behind the weight function The inner product in a $L^2$ space can be defined as:
$$\langle f,g\rangle =\int_a^b \bar{f}(x)g(x)w(x)dx$$
For Legendre polynomials, we define it as:
$$\langle P_m,P_n\rangle =\int_0^1 \bar{P}_m(x)P_n(x)dx$$
so $w(x)=1$.
But there are case in which $w(x)\neq 1$. For example, Laguerre $w(x)=e^{-x}$ and Hermite polynomials $w(x)=e^{-x^2}$.
Is there any intuition/motivation behind different weight functions of orthogonal polynomials? I think it might be related to measure theory and Sturm-Liouville problems.
 A: I'm not sure this is a great answer, but in the case of the Legendre polynomials, you are working on a compact interval, so the given inner product with weight $\equiv 1$ makes sense.
On the other hand, for the Laguerre and Hermite polynomials, you work on the intervals $[0,\infty)$ and $(-\infty, \infty)$, respectively. Since products of polynomials are not integrable on these infinite intervals, you need some weight in the inner product just to get convergence in the integrals. But you can't just choose any weight: you need weights that decay faster at $\infty$ than the reciprocal of any polynomial. Hence choosing weights like $e^{-x}$ (for the Laguerre polynomials) and $e^{-x^2}$ (for the Hermite polynomials). 
These choices seem very natural to me. I think if you were to ask a random mathematician to name a positive function on $\mathbb{R}$ that decays faster than the reciprocal of any polynomial, they would probably say $e^{-x}$.
For the Hermite polynomials, where you are working over $(-\infty, \infty)$, you need to have a weight that decays quickly at both $-\infty$ and $\infty$, hence $e^{-x^2}$.
A: I think you mean this question in one of two ways.
Either you mean why do e.g. Laguerre polynomials have that specific weight? 
The answer to which is just that you start with the weight and the polynomials follow from it. You can often in principle retrieve the weight from the polynomials though. The zeros of polynomials will be in the support of the weight, so you need a weight that satisfies
$$
\int_{support(w)} x^k w(x) dx < \infty, \qquad \forall k \geq 0.
$$
If the zeros are not bounded by a compact interval than a weight like $w=1$ won't cut it.
The other way you might have meant this question is whether the polynomials and the weight have any connecting properties that can be understood intuitively. Below I present an example of this that I came across in M. E. H. Ismail's book "Classical and Quantum Orthogonal Polynomials in One Variable".
There is some electrostatic interpretation (might help right?) behind some weights for orthogonal polynomials.
Weights are often of the form
$$
w(x) = e^{-v(x)},
$$
where $v$ is analytic on the interior of the support of the weight. 
For example


*

*$v(x)=x^2$ on $\mathbb{R}$ for Hermite

*$v(x)= a\log(x)x$ on $(0,\infty)$ for Laguerre

*$v(x)= a\log(x-1)+b\log(x+1)$ on $(-1,1)$ for Jacobi


This $v$ can the roughly be interpreted as an electrostatic potential. Then if you put $n$ charged particles in this potential, their equilibrium positions will be the zeros of the orthogonal polynomial of degree $n$ (with respect to $w$). 
This isn't the whole story! What mass and charges do the particles get for example? And in the case of Legendre one needs to add some extra static charges at the endpoints of the support for there to even be an equilibrium position.
For more details see for example section 6.7 of "Orthogonal Polynomials" by G. Szegö or maybe a bit lighter the introduction in "Electrostatic interpretation for the zeros of certain polynomials and the Darboux process" by A Grünbaum (2001).
