In the field of safety detection of fruits and vegetables, how to conduct non-destructive detection of pesticide residues is still a pressing problem to be solved. In response to the high cost and destructive nature of existing chemical detection methods, this study explored the potential of identifying different pesticide residues on Hami melon by short-wave infrared (SWIR) (spectral range of 1000–2500 nm) hyperspectral imaging (HSI) technology combined with machine learning. Firstly, the classification effects of classical classification models, namely extreme learning machine (ELM), support vector machine (SVM), and partial least squares discriminant analysis (PLS-DA) on pesticide residues on Hami melon were compared, ELM was selected as the benchmark model for subsequent optimization. Then, the effects of different preprocessing treatments on ELM were compared and analyzed to determine the most suitable spectral preprocessing treatment. The ELM model optimized by Honey Badger Algorithm (HBA) with adaptive t-distribution mutation strategy (tHBA-ELM) was proposed to improve the detection accuracy for the detection of pesticide residues on Hami melon. The primitive HBA algorithm was optimized by using adaptive t-distribution, which improved the structure of the population and increased the convergence speed. Compared the classification results of tHBA-ELM with HBA-ELM and ELM model optimized by genetic algorithm (GA-ELM), the tHBA-ELM model can accurately identify whether there were pesticide residues and different types of pesticides. The accuracy, precision, sensitivity, and F1-score of the test set was 93.50%, 93.73%, 93.50%, and 0.9355, respectively. Metaheuristic optimization algorithms can improve the classification performance of classical machine learning classification models. Among all the models, the performance of tHBA-ELM was satisfactory. The results indicated that SWIR-HSI coupled with tHBA-ELM can be used for the non-destructive detection of pesticide residues on Hami melon, which provided the theoretical basis and technical reference for the detection of pesticide residues in other fruits and vegetables.