Derivation (spherical harmonics)

Suppose $$ \begin{align*} \hat L_3 \psi = m\hbar \psi, \qquad \hat L^2 \psi = \lambda \hbar^2 \psi. \end{align*} $$

Using $\psi(\theta, \phi) = Y(\theta) Z(\phi)$, the $\hat L_3$-equation gives $$ \begin{align*} -i\hbar Z' = m\hbar Z \implies Z(\phi) = \exp(im\phi) \end{align*} $$ and since $\phi$ should be $2\pi$-periodic, we require $m\in \Z$.

Next, the $\hat L^2$-equation becomes $$ \begin{align*} \frac{1}{\sin\theta} \dd{\theta}\left(\sin\theta \dfd{Y}{\theta}\right) - \frac{m^2}{\sin^2\theta} Y = -\lambda Y. \end{align*} $$ With the substitution $x = \cos\theta$, we obtain $$ \begin{align*} \dd{x}\left((1-x^2) \dfd{Y}{x}\right) - \frac{m^2}{1-x^2} Y = -\lambda Y. \end{align*} $$ This is the general Legendre equation and the solutions are the associated Legendre functions $$ \begin{gather*} Y(x) = P_l^m(x) = (1-x^2)^{|m|/2} \dd[|m|]{x} P_l(x) = \sin^{|m|}(x) \dd[|m|]{(\cos\theta)} P_l(\cos\theta), \\ \lambda = l(l+1), \qquad l \geq |m|, \qquad l\in \Z \end{gather*} $$ where $P_l$ is the (ordinary) Legendre polynomials.