  Recent theoretical and experimental research suggests that $\theta$-TaN is a
semimetal with high thermal conductivity ($\kappa$), primarily due to the
contribution of phonons ($\kappa_\texttt{ph}$). By using first-principles
calculations, we show a non-monotonic pressure dependence of the $\kappa$ of
$\theta$-TaN. $\kappa_\texttt{ph}$ first increases until it reaches a maximum
at around 60~GPa, and then decreases. This anomalous behaviour is a consequence
of the competing pressure responses of phonon-phonon and phonon-electron
interactions, in contrast to the known materials BAs and BP, where the
non-monotonic pressure dependence is caused by the interplay between different
phonon-phonon scattering channels. Although TaN has phonon dispersion features
similar to BAs at ambient pressure, its response to pressure is different and
an overall stiffening of the phonon branches takes place. Consequently, the
relevant phonon-phonon scattering weakens as pressure increases. However, the
increased electronic density of states near the Fermi level, and specifically
the emergence of additional pockets of the Fermi surface at the high-symmetry L
point in the Brillouin zone, leads to a substantial increase in phonon-electron
scattering at high pressures, driving a decrease in $\kappa_{\mathrm{ph}}$. At
intermediate pressures ($\sim$~20$-$70~GPa), the $\kappa$ of TaN surpasses that
of BAs. Our work provides deeper insight into phonon transport in semimetals
and metals where phonon-electron scattering is relevant.
