Shockingly good victory for CHP. They've decisively beaten the AKP in major metros. They're winning in very conservative interior Anatolian provinces like Adiyaman, Kilis and Kirikkale. Was kicking out the Alevi all they needed to do to start winning again?
I would say there's two specific factors at play, perhaps just one, but more likely some combination of the two.
First, it's no secret that there was 'fudging' when it comes to the national government election, with actions that would be illegal in many countries boosting the AKP. Maybe not direct ballot box stuffing, but certainly a hostile environment for the Opposition. Such a situation is is not replicable for these contests. So one might say this result is closer to a free and fair uninfluenced measurement of the country.
Second, when a strongman leader has been in power for a long time, their brand can easily separate from their party's image. As long as the strongman maintains appearances they could remain popular even as their government isn't. Modi is another example of how he carries the BJP nationally way above the 50-50 or worse suggested by local elections. So in this situation, Erdogan announcing his eventual retirement really did dynamite the AKPs electoral foundation.
Also I suspect just general off-year things, when certain voters have more motivation than others.