\[ \boxed { {\frac {{\rm d}^{2}}{{\rm d}{x}^{2}}}y \left ( x \right ) +2\,n \left ( {\frac {\rm d}{{\rm d}x}}y \left ( x \right ) \right ) \cot \left ( x \right ) + \left ( -{a}^{2}+{n}^{2} \right ) y \left ( x \right ) =0} \]
Mathematica: cpu = 0.163021 (sec), leaf count = 114 \[ \left \{\left \{y(x)\to c_1 \left (\cos ^2(x)-1\right )^{\frac {1}{4} (1-2 n)} P_{\frac {1}{2} \left (2 \sqrt {2 n^2-a^2}-1\right )}^{\frac {1}{2} (2 n-1)}(\cos (x))+c_2 \left (\cos ^2(x)-1\right )^{\frac {1}{4} (1-2 n)} Q_{\frac {1}{2} \left (2 \sqrt {2 n^2-a^2}-1\right )}^{\frac {1}{2} (2 n-1)}(\cos (x))\right \}\right \} \]
Maple: cpu = 0.171 (sec), leaf count = 67 \[ \left \{ y \left ( x \right ) ={\it \_C1}\, \left ( \sin \left ( x \right ) \right ) ^{-n+{\frac {1}{2}}}{\it LegendreP} \left ( -{\frac { 1}{2}}+\sqrt {-{a}^{2}+2\,{n}^{2}},n-{\frac {1}{2}},\cos \left ( x \right ) \right ) +{\it \_C2}\, \left ( \sin \left ( x \right ) \right ) ^{-n+{\frac {1}{2}}}{\it LegendreQ} \left ( -{\frac {1}{2}}+\sqrt {-{a} ^{2}+2\,{n}^{2}},n-{\frac {1}{2}},\cos \left ( x \right ) \right ) \right \} \]