The accumulation of hazardous pharmaceutical wastes in aquatic organisms, particularly nonsteroidal anti-inflammatory drug molecules, has severe toxicological consequences for both aquatic life and humans. To protect the environment, it is essential to develop a highly efficient device with dual-purpose capabilities for drug detection while minimizing catalyst expenditure. In this work, we explored a simple and effective design for fabricating a magnesium stannate combined with carbon black (Mg2SnO4/CB) nanocomposite as a cost-effective, sustainable electrode material for the electrochemical detection of flutamide (Flu). The Mg2SnO4/CB nanocomposite was synthesized through a simple hydrothermal process followed by sonication. Various analytical methods were used to determine its physico-chemical characteristics. The electrochemical efficiency of Mg2SnO4/CB/GCE was evaluated by detecting Flu, showing a remarkable linear range from 0.6 to 198.4 µM with a sensitivity of 3.91 μA μM−1 cm−2. In addition, the constructed sensor demonstrated excellent selectivity, high repeatability, outstanding reproducibility, and long-lasting stability. The anti-interference experiments yielded a definite current response without any change in peak shifts. Consequently, Mg2SnO4/CB/GCE demonstrated superior performance in determining Flu in human urine and river water samples.