Extant research suggests that workplace ostracism has a detrimental impact on the outcomes of employees. However, very little is known about the impact of workplace ostracism on sleep quality. Therefore, this study aimed to address this gap in the literature. By employing the extended stressor-detachment model, we investigated the mediating role of psychological detachment and the moderating role of coping humor. We used a self-report questionnaire and a time-lagged research design to assess employees’ workplace ostracism, coping humor, psychological detachment, and sleep quality. A total of 403 valid questionnaires were obtained from participants in full-time employment in China. As predicted, the results showed that workplace ostracism is negatively associated with psychological detachment, which in turn, impairs sleep quality. We further found that high levels of coping humor buffer the negative effect of workplace ostracism on psychological detachment and sleep quality. In addition, the moderation effect of coping humor on the relationship between workplace ostracism and sleep quality is mediated by psychological detachment. Finally, based upon the results, we discuss the theoretical implications, provide practical proposals for managers and policymakers, and make suggestions for the direction of further research.