I was told to never divide both sides of an equation by a trigonometric function in case I accidentally eliminate an answer (or divide by $0$).

However, why do we divide both sides by $\cos x$ for $\sin x = \cos x$. How do I know whether I can divide or not by a trigonometric function?

Thank you.