\[ y''(x)=-a^2 n y(x) \sec ^2(a x) \left ((n-1) \sin ^2(a x)+\cos ^2(a x)\right )-a (n-1) \sin (2 a x) \sec ^2(a x) y'(x) \] ✓ Mathematica : cpu = 0.153011 (sec), leaf count = 81
DSolve[Derivative[2][y][x] == -(a^2*n*Sec[a*x]^2*(Cos[a*x]^2 + (-1 + n)*Sin[a*x]^2)*y[x]) - a*(-1 + n)*Sec[a*x]^2*Sin[2*a*x]*Derivative[1][y][x],y[x],x]
\[\left \{\left \{y(x)\to c_1 e^{-i a x} \cos ^{n-1}(a x)-\frac {i c_2 e^{2 i a x} \left (\frac {1}{2} e^{-i a x}+\frac {1}{2} e^{i a x}\right )^n}{a \left (1+e^{2 i a x}\right )}\right \}\right \}\] ✓ Maple : cpu = 0.104 (sec), leaf count = 27
dsolve(diff(diff(y(x),x),x) = -a*(n-1)*sin(2*a*x)/cos(a*x)^2*diff(y(x),x)-n*a^2*((n-1)*sin(a*x)^2+cos(a*x)^2)/cos(a*x)^2*y(x),y(x))
\[y \left (x \right ) = c_{1} \left (\cos ^{n}\left (a x \right )\right )+c_{2} \left (\cos ^{n -1}\left (a x \right )\right ) \sin \left (a x \right )\]