\[ \int (d \cot (e+f x))^n (a+i a \tan (e+f x))^2 \, dx \]
Optimal antiderivative \[ \frac {a^{2} d \left (d \cot \! \left (f x +e \right )\right )^{-1+n}}{f \left (1-n \right )}-\frac {2 a^{2} d \left (d \cot \! \left (f x +e \right )\right )^{-1+n} \hypergeom \! \left (\left [1, -1+n \right ], \left [n \right ], \mathrm {-I} \cot \! \left (f x +e \right )\right )}{f \left (1-n \right )} \]
command
Integrate[(d*Cot[e + f*x])^n*(a + I*a*Tan[e + f*x])^2,x]
Mathematica 13.1 output
\[ \int (d \cot (e+f x))^n (a+i a \tan (e+f x))^2 \, dx \]
Mathematica 12.3 output
\[ -\frac {e^{-2 i e} \left (1+e^{2 i (e+f x)}\right )^{-n} \left (\frac {i \left (1+e^{2 i (e+f x)}\right )}{-1+e^{2 i (e+f x)}}\right )^{n-1} \cos ^2(e+f x) (a+i a \tan (e+f x))^2 \left (2^n \left (1+e^{2 i (e+f x)}\right ) \, _2F_1\left (1-n,1-n;2-n;\frac {1}{2} \left (1-e^{2 i (e+f x)}\right )\right )-\left (1+e^{2 i (e+f x)}\right )^n\right ) \cot ^{-n}(e+f x) (d \cot (e+f x))^n}{f (n-1) (\cos (f x)+i \sin (f x))^2} \]