Coastal aquifers in southern Bangladesh are increasingly threatened by groundwater overexploitation, saltwater intrusion, and diffuse contamination, posing serious risks to safe water supply. While earlier studies have primarily examined salinity and overall water quality degradation, the spatial dynamics and controlling factors of nitrate (NO₃−) and sulfate (SO₄2−) contamination remain poorly constrained. This study introduces a novel explainable artificial intelligence (XAI) framework that integrates Conditional Inference Trees (CIT), Multiple Correspondence Analysis (MCA), and advanced machine learning (ML) algorithms to predict NO₃− and SO₄2− concentrations and elucidate their governing hydrogeochemical mechanisms. A total of 590 groundwater samples and 11 hydrochemical and environmental predictors were analyzed using CatBoost, Gradient Boosting Regression (GBR), and Artificial Neural Network (ANN) models. The tree-based CatBoost and GBR models were used for structured learning, while ANN captured complex non-linear dependencies, enabling a robust comparative assessment. Results show that saltwater intrusion and domestic wastewater discharge are the dominant drivers of SO₄2− enrichment, whereas agricultural fertilizer inputs and salinity gradients control NO₃− variability. SHAP-based interpretability analysis identified salinity, Ca2+, and Na+ as the key predictors for SO₄2−, and salinity and K+ for NO₃−. MCA delineated contamination hotspots linked to anthropogenic activities and hydrogeochemical interactions. Learning curve analysis confirmed stable model performance without overfitting, while baseline model comparisons demonstrated that the proposed CatBoost and ANN frameworks achieved up to 4.5× higher predictive accuracy, underscoring their robustness and generalization capability. This study presents one of the first XAI-driven evaluations of NO₃− and SO₄2− contamination in coastal Bangladesh. By coupling interpretability with predictive modeling, it advances the understanding of multi-source groundwater contamination processes and provides a transferable decision-support framework for sustainable groundwater management in vulnerable coastal environments.