Through the COVID-19 health crisis, a plethora of new medications, along with some discontinued pharmaceuticals, were directly tested on population to assess their efficacy in symptom management. Consequently, residues from these treatments were systematically disposed into sewage systems, presenting a novel contamination challenge in urban centers. To effectively address this issue by environmental authorities, the presence of these pollutants in wastewater must be accurately quantified. Herein, we conducted a meticulous study to validate an analytical method based on solid-phase extraction (SPE) and high-performance liquid chromatography coupled with tandem mass spectrometry (HPLC-MS/MS) to detect six pharmaceuticals (metformin, famotidine, indomethacin, dexamethasone, azithromycin, and ivermectin) in wastewater. Using a Plackett-Burman design (PBD), the eight parameters significantly impacting on the HPLC-MS/MS technique were established based on the analytical signal of the six analytes. Subsequently, in conjunction with a Box-Behnken design (BBD), optimal analysis conditions were determined as follows: injection volume: 10 µL, column temperature: 20 °C, capillary voltage: 4100 V, drying gas temperature and flow rate of 350 °C and 7 L min−1 respectively, nebulizer pressure: 15 psi, concentration of formic acid and ammonium acetate in the mobile phase of 0.1 % and 10 mmol/L, respectively. SPE was optimized through a univariable experimental design. OASIS HLB cartridges exhibited the highest extraction efficiency compared to highly polar and non-polar adsorbents. The optimal sample loading conditions were set as 250.0 mL of water sample at pH = 9.0. The washing conditions were 5.0 mL of a 95:5 water:methanol solution, while elution conditions were optimal using 6.0 mL of a 98:2 methanol:formic acid solution. After evaporating the eluate to dryness and reconstituting in 1.0 mL of a 98:2 methanol:formic acid solution, a concentration factor of 250 was achieved. The analytical method was validated using for matrices, namely, raw and treated wastewater, wastewater percolated through soil and groundwater. Acceptable levels of precision and accuracy were achieved for all analytes in the tested matrices. Using the validated method, the six pharmaceuticals were quantified in environmental samples, revealing high levels of metformin, dexamethasone, and azithromycin in Mexico City’s sewage. Highly polar compounds displayed mobility through environment as they were present in effluent samples, percolated wastewater, and groundwater.