Capsular diversity of Streptococcus pneumoniae constitutes a major obstacle in eliminating the pneumococcal disease. Such diversity is genetically encoded by almost 100 variants of the capsule polysaccharide locus (cps). However, the evolutionary dynamics of the capsule -- the target of the currently used vaccines -- remains not fully understood. Here, using genetic data from 4,469 bacterial isolates, we found cps to be an evolutionary hotspot with elevated substitution and recombination rates. These rates were a consequence of altered selection at this locus, supporting the hypothesis that the capsule has an increased potential to generate novel diversity compared to the rest of the genome. Analysis of twelve serogroups revealed their complex evolutionary history, which was principally driven by recombination with other serogroups and other streptococci. We observed significant variation in recombination rates between different serogroups. This variation could only be partially explained by the lineage-specific recombination rate, the remaining factors being likely driven by serogroup-specific ecology and epidemiology. Finally, we discovered two previously unobserved mosaic serotypes in the densely sampled collection from Mae La, Thailand, here termed 10X and 21X. Our results thus emphasise the strong adaptive potential of the bacterium by its ability to generate novel serotypes by recombination.