Pest detection is a crucial aspect of rice production. Accurate and timely identification of rice pests can assist farmers in taking prompt measures for control. To enhance the precision and real-time performance of rice pest detection, this paper introduces a novel YOLOv8-SCS architecture that integrates Space-to-Depth Convolution (SPD-Conv), Context Guided block (CG block), and Slide Loss. Initially, the original algorithm's convolutional module is improved by introducing the SPD-Conv module, which reorganises the input channel dimensions into spatial dimensions, enabling the model to capture fine-grained pest features more efficiently while maintaining a lightweight model architecture. Subsequently, the CG block module is integrated into the CSPDarknet53 to 2-Stage FPN (C2f) structure, maintaining the model’s lightweight nature while enhancing its feature extraction capabilities. Finally, the Binary Cross-Entropy (BCE) is refined by incorporating the Slide Loss function, which encourages the model to focus more on challenging samples during training, thereby improving the model's generalization across various samples. To validate the effectiveness of the improved algorithm, a series of experiments were conducted on a rice pest dataset. The results demonstrate that the proposed model outperforms the original YOLOv8 in rice pest detection, achieving an mAP of 87.9%, which is a 5.7% improvement over the original YOLOv8. The model also features a 44.1% reduction in parameter count and a decrease of 11.7 GFLOPs in computational requirements, meeting the demands for real-time detection.