\[ y(x) \left (-a \cos ^2(x)-(n-1) n\right )+\cos ^2(x) y''(x)=0 \] ✓ Mathematica : cpu = 0.378629 (sec), leaf count = 134
DSolve[(-((-1 + n)*n) - a*Cos[x]^2)*y[x] + Cos[x]^2*Derivative[2][y][x] == 0,y[x],x]
\[\left \{\left \{y(x)\to c_1 i^{1-n} \cos ^{1-n}(x) \, _2F_1\left (-\frac {n}{2}-\frac {i \sqrt {a}}{2}+\frac {1}{2},-\frac {n}{2}+\frac {i \sqrt {a}}{2}+\frac {1}{2};\frac {3}{2}-n;\cos ^2(x)\right )+c_2 i^n \cos ^n(x) \, _2F_1\left (\frac {n}{2}-\frac {i \sqrt {a}}{2},\frac {n}{2}+\frac {i \sqrt {a}}{2};n+\frac {1}{2};\cos ^2(x)\right )\right \}\right \}\] ✓ Maple : cpu = 0.298 (sec), leaf count = 123
dsolve(cos(x)^2*diff(diff(y(x),x),x)-(a*cos(x)^2+n*(n-1))*y(x),y(x))
\[y \left (x \right ) = c_{1} \sin \left (2 x \right ) \left (\cos ^{-n}\left (x \right )\right ) \hypergeom \left (\left [1-\frac {i \sqrt {a}}{2}-\frac {n}{2}, 1+\frac {i \sqrt {a}}{2}-\frac {n}{2}\right ], \left [\frac {3}{2}-n \right ], \frac {\cos \left (2 x \right )}{2}+\frac {1}{2}\right )+\frac {c_{2} \left (-2 \cos \left (2 x \right )+2\right )^{\frac {3}{4}} \hypergeom \left (\left [\frac {1}{2}+\frac {i \sqrt {a}}{2}+\frac {n}{2}, \frac {1}{2}-\frac {i \sqrt {a}}{2}+\frac {n}{2}\right ], \left [n +\frac {1}{2}\right ], \frac {\cos \left (2 x \right )}{2}+\frac {1}{2}\right ) \left (\cos ^{n}\left (x \right )\right ) \left (2 \cos \left (2 x \right )+2\right )^{\frac {1}{4}}}{\sqrt {\sin \left (2 x \right )}}\]