When we change variables from $x$ to $z(x)$ what we're doing is effectively looking for a function $z$ that shifts $y$ and its derivatives so that $p(x)$ and $q(x)$ are fixed relative to them, allowing us to consider $p$ and $q$ as constants in this new variable.
By the chain rule,
\begin{equation}
\frac{\mathrm d}{\mathrm{d}x} y(z(x)) = \frac{\mathrm d}{\mathrm{d}z} y(z) \frac{\mathrm{d}z}{\mathrm{d}x}
\end{equation}
and
\begin{equation}
\frac{\mathrm d}{\mathrm{d}x} (\frac{\mathrm d}{\mathrm{d}z} y(z) \frac{\mathrm{d}z}{\mathrm{d}x}) = \frac{\mathrm{d}^2}{\mathrm{d}z^2} y(z) (\frac{\mathrm{d}z}{\mathrm{d}x})^2 +\frac{\mathrm d}{\mathrm{d}z} y(z) \frac{\mathrm{d}^2 z}{\mathrm{d}x^2}
\end{equation}.
Substituting into the original equation and rearranging, we get
\begin{equation}
y''(z) +y'(z)(\frac{z''(x) +p(x)z'(x)}{(z'(x))^2}) + \frac{q(x)}{(z'(x))^2} y(z) = 0
\end{equation}
And so for the new coefficients to be constant, we require $\frac{z''(x) +p(x)z'(x)}{(z'(x))^2}= A_1$ and $\frac{q(x)}{(z'(x))^2} = \frac{1}{A_2}$ where $A_1,A_2$ are constants.
the second of these is easier to solve, giving us $z'(x) = \sqrt{A_2q(x)}$, which we can differentiate to give \begin{equation}z''(x) = \frac{1}{2}\frac{A_2}{\sqrt{A_2 q(x)}} q'(x) \end{equation} We can then plug this into the equation for the other coefficient and solve for $z$,
\begin{equation}
\frac{\frac{1}{2}\frac{A_2}{\sqrt{A_2 q(x)}} q'(x) +p(x)\sqrt{A_2 q(x)}}{A_2 q(x)} = A_1
\end{equation} Multiplying the top and bottom of the LHS by $\sqrt{A_2 q(x)}$ and rearranging gives us
\begin{equation}
\frac{q'(x) + 2p(x)q(x)}{q(x)^\frac{3}{2}} = 2\sqrt{A_2}A_1
\end{equation} and so the desired expression is clearly constant.
You have an argument that
$$
f(D)=(D-3)^3(D^2+1)P(D)
$$
for some polynomial $P$. Thus, the degree of $f$ is at least $5$. But, we do not know if there are other solutions in $f(D)y=0$, origin from $P$. Thus, we know that the least degree of $f$ is $5$, but we have no upper bound.
For example, the function you mention also solves
$$
(D-3)^3(D^2+1)(D+2)(D-7)y=0.
$$
and
$$
(D-3)^3(D^2+1)y=0.
$$
The first one of these has degree 7, the second degree 5.
Does this answers your question completely?
Best Answer
Given that problem, I would notice that the solution is of the form $y=e^{ax}(c_{1}\sin bx + c_{2}\cos bx)$
Where $a\pm bi$ are the roots to the characteristic equation of the 2nd order ODE, with $a = -1, b = 3$.
So if our 2nd order ODE is of the form $y'' + Ay' + C = 0$, then it is simple to prove that:
$(-1+3i)(-1-3i) = C \Rightarrow C = 10$
$-(-1+3i -1 -3i) = A \Rightarrow A = 2$
Then the second order ODE is:
$y'' +2y'+10=0$