Alonso and then Ferrari manager Matiacci had their own problems. During the contract renewal negotiations, their relationship further deteriorated, which eventually led to the complete collapse of both sides, and Ferrari could not stay any longer. -That's why Alonso left Ferrari.
Since the road of "renewing the contract with the original team" doesn't work, there is only the road of "finding a new team again". According to various conditions (the driver's seat of the team is vacant, the team has the strength to compete for the world championship continuously and can meet Alonso's salary requirements), only McLaren is left. -That's why Alonso joined McLaren.