Horizontal gene transfer of heavy metal resistance genes and antibiotic resistance genes in bacteria frequently occurred during composting. However, the relevancy between heavy metal pollution with different degrees and the occurrence of horizontal gene transfer during composting was unclear. Therefore, this study aimed to clarify the underlying relationship. The changes of resistance gene abundance and network analysis results showed that heavy metal pollution induced high level of resistance gene abundance in microorganisms and promoted the occurrence of horizontal gene transfer. Furthermore, regression fitting models indicated that the relevancy between resistance genes abundance and horizontal gene transfer under high pollution (HP: R = 0.90) was weakener than that under low pollution (LP: R = 0.95) and medium pollution (MP: R = 0.97). Ultimately, structural equation models further verified that the abundance of resistance genes was mainly caused by horizontal gene transfer during LP (coefficients: 0.997) and MP (coefficients: 0.993) composting. However, the high level of resistance gene abundance was caused by host bacteria (coefficients: 0.775) and horizontal gene transfer (coefficients: 0.701) during HP composting. The serious heavy metal pollution had selection pressure on host bacteria to induce them to develop resistance during HP composting, rather than only through horizontal gene transfer. Therefore, mild heavy metal pollution was more liable to cause horizontal gene transfer and increase the spread risk of resistance genes during composting. This study helped to better understand the risks caused by heavy metal pollution by evaluating the frequency of horizontal gene transfer at different pollution levels during composting.