Solution (source code)

= Solution

On an interval with $\sin x\ne0$, divide by $\sin x$ and use <integrating factor> $1/\sin x$. Then
$$
\left(\frac y{\sin x}\right)'=\frac{\cos^3x}{\sin^2x}.
$$
Put $u=\sin x$ in the integral: $\int\cos^3x\,dx/\sin^2x=\int(u^{-2}-1)du=-u^{-1}-u+C$. Multiplying back gives
$$
\boxed{y(x)=-1-\sin^2x+C\sin x.}
$$
Although the derivation divided by $\sin x$, this final expression is smooth and directly satisfies the original undivided equation at every real $x$, including multiples of $\pi$.