You either die a hero, or live long enough to see yourself become the villain.
Harvey Dent, The Dark Knight (2008).
The above dialogue is overused AF, but it is always apt.
Let me flash back a little.
Iker Casillas left Real Madrid in bad circumstances in 2015, after being repeatedly booed by the demanding Bernabeu crowd and not getting a proper institutional farewell. He had turned into a villain for Real Madrid (fair or not, different discussion).
What if Casillas has left after that historic Decima in 2014? Casillas definitely would be remembered more fondly by the Madrid fanbase and would have gotten a much better farewell from his club.
Zidane decided to leave when the club still was in a cycle of success and a moment of history, as he himself has told it clearly. He didn’t fall into that trap of wanting more success, like Iker did in 2014/15 or Pep did in the beginning of 2011/12 (Guillem Balague’s book on Pep talks about it). Its an extremely hard decision to take, when you are high on success and you see more success ahead (I am under the impression that this RM has no UCL challengers for another season atleast).
Was it necessary? Zidane felt so. I think he might be justified. Some days back, I had written an answer trying to figure out why Real Madrid struggles in La Liga, especially under Zidane- Aditya Gaonkar's answer to What exactly does Real Madrid C.F. needs to do to win La Liga? Why can't they be consistent like Barcelona? and I had commented that even if Zidane wraps up the CL hattrick, he ought to face some scrutiny for his league struggles this season. And guess what, he told explicitly that winning the league was his best moment as a coach:
Zidane says, despite winning three UCLs, his best moment as Madrid coach was winning La Liga— Rik Sharma (@riksharma_) May 31, 2018
2017/18 was a near disaster for Real Madrid, saved by their CL campaign. If they had narrowly missed out the league, Zidane probably would have given another season at RM a shot, but that disastrous league campaign probably made Zidane think that he can’t give it his all anymore and he can’t depend on a fickle competition like the CL to save the season (despite all those black magic jokes xD). Personally speaking, Zidane has a lot to learn as a tactician and I don’t think La Liga would be any more kinder towards him next season (despite Barca’s mess, the other clubs are moving towards interesting directions and I can see La Liga’s big 2/3 getting thorny matches in the league). In the answer I’ve mentioned in the above paragraph, I had written that if Zidane can’t do rigorous tactical work, he needs an assistant for it.
To put it in a nutshell, Zidane left Real Madrid because he thought that his cycle was ending and he wanted to go out on a high. As to if it was necessary, time will tell. Given his brilliant handling of all that politics associated with Real Madrid, I think he could have done a lot more with a tactically capable assistant, but he took a decision hard on him and the club, thinking it is for the better. I admire those guts from him.