It can be shown that any expression of the form $a\cos(\theta)+b\sin(\theta)$ ($a$ and $b$ are constants) can be written in the form $m\cos(\theta+c)$, where $m$ and $c$ are constants. Specifically, by taking $m=\text{sgn}(a)\sqrt{a^2+b^2}$ and $c=-\tan^{-1}\left(\frac{b}{a}\right)$, where $\text{sgn}(a)$ denotes the sign of $a$, we can write
$$a\cos(\theta)+b\sin(\theta)=\text{sgn}(a)\sqrt{a^2+b^2}\cos\left(\theta-\tan^{-1}\frac{b}{a}\right)$$
Substituting $a=-k$ and $b=1$ gives
\begin{align*}
\sin(\theta)-k\cos(\theta) &= \text{sgn}(-k)\sqrt{(-k)^2+1^2}\cos\left(\theta-\tan^{-1}\frac{1}{-k}\right)\\
&=-\text{sgn}(k)\sqrt{1+k^2}\cos\left(\theta+\tan^{-1}\frac{1}{k}\right)
\end{align*}
so if $k>0$, your equation boils down to
$$-\sqrt{1+k^2}\cos\left(\theta+\cot^{-1}k\right)=\frac{m_1}{m_2}$$
Dividing both sides by $-\sqrt{1+k^2}$ gives $\cos\left(\theta+\cot^{-1}k\right)=-\frac{m_1}{m_2\sqrt{1+k^2}}$, provided that $\left|-\frac{m_1}{m_2\sqrt{1+k^2}}\right|\leq 1$.
It can be shown that for any real number $y$ with $|y|\leq 1$, the only solutions to the equation $\cos(x)=y$ are of the form $x=2\pi m\pm\arccos(y)$ for integer $m$, so
$$\theta+\cot^{-1}(k)=2\pi m\pm\arccos\left(-\frac{m_1}{m_2\sqrt{1+k^2}}\right)$$
The desired result immediately follows.
$$\theta=2\pi m-\cot^{-1}(k)\pm\arccos\left(-\frac{m_1}{m_2\sqrt{1+k^2}}\right)$$