The investigation focused on creating and studying a new 2D–2D S-scheme CdS/g-C3N4 heterojunction photocatalyst. Various techniques examined its structure, composition, and optical properties. This included XRD, XPS, EDS, SEM, TEM, HRTEM, DRS, and PL. The heterojunction showed a reduced charge recombination rate and more excellent stability, helping to lessen photocorrosion. This was due to photogenerated holes moving more quickly out of the CdS valence band. The interface between g-C3N4 and CdS favored a synergistic charge transfer. A suitable flat band potential measurement supported enhanced reactive oxygen species (ROS) generation in degrading 4-nitrophenol and 2-nitrophenol. This resulted in remarkable degradation efficiency of up to 99% and mineralization of up to 79%. The findings highlighted the practical design of the new 2D–2D S-scheme CdS/g-C3N4 heterojunction photocatalyst and its potential application in various energy and environmental settings, such as pollutant removal, hydrogen production, and CO2 conversion.