Background Despite cognitive inflexibility is trait like in obsessive compulsive disorder (OCD) patients and underlies clinical symptomatology, it is elusive at what stage of information processing deficits, leading to cognitive inflexibility, emerges. We hypothesize that inhibitory control mechanisms during early stimulus categorization and integration into a knowledge system underlie these deficits. Methods We examined N = 25 adolescent OCD patients and matched healthy controls (HC) in a paradigm manipulating the importance of the knowledge system to perform task switching. This was done using a paradigm in which task switches were signaled either by visual stimuli or by working memory processes. This was combined with event‐related potential recordings and source localization. Results Obsessive compulsive disorder patients showed increased switch costs in the memory as compared with the cue‐based block, while HC showed similar switch costs in both blocks. At the neurophysiological level, these changes in OCD were not reflected by the N2 and P3 reflecting response‐associated processes but by the P1 reflecting inhibitory control during sensory categorization processes. Activation differences in the right inferior frontal gyrus and superior temporal gyrus are associated with the P1 effect. Conclusions Cognitive flexibility in adolescent OCD patients is strongly modulated by working memory load. Contrary to common sense, not response‐associated processes, but inhibitory control mechanisms during early stimulus categorization processes are likely to underlie cognitive inflexibility in OCD. These processes are associated with right inferior frontal and superior temporal gyrus mechanisms.