Explainable AI (XAI) has gained prominence in Intrusion Detection Systems (IDS) to address the opacity of black-box models. However, existing efforts have largely confined XAI to post-hoc interpretability, with limited exploration of its potential for driving data refinement and model optimisation. To the best of our knowledge, SHAPRefine is the first model-agnostic feature selection framework that systematically integrates class-wise SHAP value aggregation with automated refinement to produce lightweight and high-performing IDS models. Unlike existing SHAP-based methods that repeatedly recompute Shap-ley values for each candidate subset-often requiring excessive retraining and parameter tuning-SHAPRefine introduces a performance-driven iterative selection strategy that minimizes redundant computations while explicitly accounting for minority-class contributions. Comprehensive evaluations across diverse IDS datasets and classifiers demonstrate that SHAPRefine consistently reduces feature dimensionality by up to 90%, cuts training time and energy consumption, and improves detection accuracy across all attack types, with F1-score gains of up to 95% for minority classes. These results establish SHAPRefine as a robust and resource-efficient solution for accurate IDS deployment in Beyond 5G (B5G) and 6G networks.