The accurate prediction of the residual strength of defective pipelines is a critical prerequisite for ensuring the safe operation of oil and gas pipelines, and it holds significant implications for the pipeline’s remaining service life and preventive maintenance. Traditional machine learning algorithms often fail to comprehensively account for the correlative factors influencing the residual strength of defective pipelines, exhibit limited capability in extracting nonlinear features from data, and suffer from insufficient predictive accuracy. Furthermore, the predictive models typically lack interpretability. To address these issues, this study proposes a hybrid prediction model for the residual strength of defective pipelines based on Bayesian optimization (BO) and eXtreme Gradient Boosting (XGBoost). This approach resolves the issues of excessive iterations and high computational costs associated with conventional hyperparameter optimization methods, significantly enhancing the model’s predictive performance. The model’s prediction performance is evaluated using mainstream metrics such as the Mean Absolute Percentage Error (MAPE), Coefficient of Determination (R2), Root Mean Square Error (RMSE), robustness analysis, overfitting analysis, and grey relational analysis. To enhance the interpretability of the model’s predictions, reveal the significance of features, and confirm prior domain knowledge, Shapley additive explanations (SHAP) are employed to conduct the relevant research. The results indicate that, compared with Random Forest, LightGBM, Support Vector Machine, gradient boosting regression tree, and Multi-Layer Perceptron, the BO-XGBoost model exhibits the best prediction performance, with MAPE, R2, and RMSE values of 5.5%, 0.971, and 1.263, respectively. Meanwhile, the proposed model demonstrates the highest robustness, the least tendency for overfitting, and the most significant grey relation degree value. SHAP analysis reveals that the factors influencing the residual strength of defective pipelines, ranked in descending order of importance, are defect depth (d), wall thickness (t), yield strength (σy), external diameter (D), defect length (L), tensile strength (σu), and defect width (w). The development of this model contributes to improving the integrity management of oil and gas pipelines and provides decision support for the intelligent management of defective pipelines in oil and gas fields.