Khamenei never allows another politician to be a threat to his complete grasp of power in Iran. Ahmadinejad, Larijani, Ghalibaf, they all were conservative politicians that Khamenei put aside because they were becoming too powerful.
Khamenei set the stage for Pezeshkian this time. It was possibly the lamest and most obvious election manipulation that he's been doing for decades. The Ghalibaf-Jalili dilemma served no purpose but to divide the conservatives to help a reformist win the election. The chance of a reformist winning the election was zero, particularly because of super low turnout in cities that vote for the reformists, but somehow he managed to pick a reformist out of the ballot for this sensitive period in Iran's history (Trump back in power, snapback mechanism, economic depression, energy cuts, etc.)