Factorization means, that for any differentiable function $f(x)$, and for some $a(x)$ and $b(x)$ we have:
$$
(D^2 - (x^2+1)) \circ f(x) = f^{\prime\prime}(x) - (x^2+1) f(x) = \left( D + a(x) \right) \left(D + b(x) \right) \circ f(x)
$$
Start expanding the right-hand-side:
$$\begin{eqnarray}
\left( D + a(x) \right) \left(D + b(x) \right) \circ f(x) &=& \left( D + a(x) \right) \circ \left( f^{\prime}(x) + b(x) f(x)\right) \\ &=& f^{\prime\prime}(x) + \left(b(x) f(x)\right)^\prime + a(x) f^\prime(x) + a(x) b(x) f(x) \\
&=& f^{\prime\prime}(x) + \left( a(x) + b(x) \right) f^\prime(x) + \left( a(x) b(x) + b^\prime(x) \right) f(x)
\end{eqnarray}
$$
Since the identity must hold for arbitrary $f(x)$ we should have $a(x) + b(x) = 0$ and $a(x) b(x) + b^\prime(x) = -x^2-1$, giving $a(x) = -b(x) = x$. Thus
$$
(D^2 - (x^2+1)) = (D + x)( D-x)
$$