Recently, wide phonon bandgaps have been found to play an essential role in thermal transport in some semiconductors, such as GaN, where there is a sensitive dependence of the thermal conductivity on isotopes and lattice defects. We explore the effect of carbon and indium substitution on thermal transport in bulk and monolayer GaN from a first-principles approach. Our calculations reveal that the low-frequency phonon modes below the phonon bandgap make dominant contributions to thermal transport. Our phonon mode analysis demonstrates that after the atom substitution, the reduced phonon bandgap and localized vibrations expand the phonon scattering space, thus leading to a large suppression of phonon lifetimes, which is the primary reason for the significant reduction in thermal conductivity. Our findings provide insights on an atomistic scale into the physical mechanism of the effects of atom substitution on thermal transport in GaN, and our results may guide to enhanced thermal management.