Heavy metals (HMs) are widely recognized for their toxicity and have serious environmental implications as technology advances and public pressure mounts to guarantee the safest and healthiest environment. This study evaluates the phytoremediation potential of HMs i.e., Copper (Cu), Zinc (Zn), Lead (Pb), and Cadmium (Cd) by Calotropis procera (Aiton) W.T. Aiton, also known as Sodom apple, along an urban–rural gradient and its effect on communities’ diversity, forage and medicinal quality in semi-arid region of Khyber Pakhtunkhwa Pakistan. The HM concentration was investigated along with the urban–rural gradients by sampling C. procera and soil samples. Acid-digested samples were tested for metal concentration using an atomic absorption spectrophotometer (AAS). We used principal component analysis and cluster analysis to identify the pattern of metal distribution in plants and soil. To comprehend the species’ diversity of plant communities in polluted sites, the species’ composition of C. procera communities was explored. Our results showed that the concentration of HMs in the soil and plant decreased from Zn to Cd (Zn > Cu > Pb > Cd). Likewise, more than half of the soil metal accumulated in the roots and aerial part of the plant, indicating the bioaccumulation potential of the plant species for these metals. Zn, Cu, Pb, and Cd translocation ratio varied from root > stem > leaf > flower. Root to stem transfer of metal was poor, but strongly mobilized to the leaves when available in the stems. Carthamus lanatus, Sonchus asper, Cynodon dactylon, Xanthium strumarium, and Silybum marianum were the leading species in three groups of 36 plant species. Pearson’s correlation revealed a significant relationship between HM concentrations and diversity indices. Zn and Cu content in the soil influenced plant species richness, Shannon–Wiener index (H′), and evenness index (Eh). Given the environmental toxicity of HMs, Cd concentrations in soil exceeded the permissible level, suggesting residents should be warned about potential health risks. As a result, the species chosen for this study can be employed as a biomonitor and phytoremediator of soil contaminated by these HMs, as it can accumulate HMs to a toxic level.