The basic principle that is useful for addressing the issue you are talking about is conservation of entropy. In thermal equilibrium, the comoving entropy is conserved, and this can be used to find out how the temperature changes with the expansion of the universe.
Since the entropy density of relativistic species usually dominate the total entropy, it is useful to define the total entropy in terms of an effective number of relativistic degrees of freedom (for entropy), $g_{*\text{S}}$
\begin{equation}
s_\text{tot} = g_{*\text{S}} \frac{2 \pi^2}{45}T^3,
\end{equation}
where
\begin{equation}
g_{*\text{S}} = \sum_{\text{bosons}} g_i \left(\frac{T_i}{T}\right)^3 + \frac{7}{8} \sum_{\text{fermions}} g_i \left(\frac{T_i}{T}\right)^3,
\end{equation}
where $T$ is the temperature of the heat bath, and we have allowed for the possibility that some relativistic species have decoupled from the heat bath and have a different temperature, $T_i$. Note that we have also assumed here that the chemical potentials are negligible.
Assuming that the comoving entropy density is constant in time we get
\begin{equation}
\frac{d }{d t} \left(s a^3\right) = 0.\tag{1}
\end{equation}
This means that we can directly relate the temperature, $T$, and the scale factor, $a$
\begin{equation}
T \propto \frac{g_{*\text{S}}^{-1/3}(T)}{a}.\tag{2}
\end{equation}
So we see that as long as the number of relativistic degrees of freedom, $g_{*\text{S}}$, does not change then we have $T \sim 1/a$, and your (1) and (2) are compatible.
If the number of relativistic degrees of freedom changes, then your equation (2) is not valid any more. This is because heat is either added to or subtracted from the heat bath, increasing or decreasing the comoving number of particles of any given species.
(1) will always be valid, however, as long as a species is in thermodynamic equilibrium (with no chemical potential).