13 and 17 are prime numbers, which is hypothesized as one of the reasons:
Imagine a predator feeding on these cicadas; this unlucky creature would have to wait 16 years to feed again. If this predator were to adapt evolutionarily, he may start feeding on other stuff too (or maybe hibernate). Say he starts adapting and stays in the ground for 1 year, appearing every 2 years. Problem is, 17 can't be divided by two, so he would have to wait till 17*2=34 years 'till he meets his cicada meal again. If he adapts further – say 3 years – the timespan gets even bigger, and by the time-point he stays in the ground 16 years, he will see cicadas only every 17*16=272 years. Being denied food for so long is not practical at all, and this is one of the hypotheses for why there's no predators specialized for preying on adult cicadas of the Magicicada genus.
A second hypothesis, supported by mathematical models, sustains the view that the precise nature of the cycles helps the cicadas prevent hybridization with other species. While hybridization is not necessarily destructive in all cases, it can usually lead to detrimental effects when the adaptations in the parents are “diluted” in the hybrids.