Given differential equation can be rewritten as
$\frac{d y}{d x}+2 y \,\cot\, x=cosec\, x$
It is a linear differential equation of the form
$\frac{d Y}{d x}+P_{Y}=Q $
Here, $ P=2 \cot x$ and $ Q=cosec \,x$
$\therefore IF =e^{\int P\, d x}=e^{2 \int \cot \,x \,d x}$
$=e^{2 \log \sin x}=e^{\log \sin ^{2} x}=\sin ^{2} x$