Given a linear second-order differential operator $${\mathcal {L}}\equiv \phi \,D^2+\psi \,D$$ with non zero polynomial coefficients of degree at most 2, a sequence of real numbers $$\lambda _n$$ , $$n\geqslant 0$$ , and a Sobolev bilinear form $$\begin{aligned} {\mathcal {B}}(p,q)\,=\,\sum _{k=0}^N\left\langle {{\mathbf {u}}_k,\,p^{(k)}\,q^{(k)}}\right\rangle , \quad N\geqslant 0, \end{aligned}$$ where $${\mathbf {u}}_k$$ , $$0\leqslant k \leqslant N$$ , are linear functionals defined on polynomials, we study the orthogonality of the polynomial solutions of the differential equation $${\mathcal {L}}[y]=\lambda _n\,y$$ with respect to $${\mathcal {B}}$$ . We show that such polynomials are orthogonal with respect to $${\mathcal {B}}$$ if the Pearson equations $$D(\phi \,{\mathbf {u}}_k)=(\psi +k\,\phi ')\,{\mathbf {u}}_k$$ , $$0\leqslant k \leqslant N$$ , are satisfied by the linear functionals in the bilinear form. Moreover, we use our results as a general method to deduce the Sobolev orthogonality for polynomial solutions of differential equations associated with classical orthogonal polynomials with negative integer parameters.