That Jesus died was necessary - he was a mortal Man. Like you and me; Jesus could only become immortal via the portals of biological death: mortal death is necessary to immortal resurrection.
(I cannot explain by what mechanism this is so, but it apparently is a constraint of our created reality.)
But Jesus was fully divine in his powers before he died - we know this because he was a divine creator, able to create divinely. That is the significance of the resurrection of Lazarus in particular, but also some others of the other miracles; these demonstrate that Jesus was a primary creator.
Being on the one hand a mortal Man, but on the other hand having this divine creative power, meant that although must die sooner-or-later, he could (in principle) often elude death here-and-now.
And there are examples in the Fourth Gospel when Jesus does this - for instance John 8:59 "Then took they up stones to cast at him: but Jesus hid himself, and went out of the temple, going through the midst of them, and so passed by."
So, sometimes - either by his behaviour, or through miraculous means, Jesus chose to delay his own death. This happened many times through the three years of his ministry, between the baptism by John and the death by crucifixion - during which Jesus was fully-divine, and had miraculous powers - but also, in general terms, he made decisions that kept him alive.
But at a certain point, Jesus stopped doing this, let events take their course, and ultimately allowed himself to be crucified.
Ordinary mortal people may be called-upon to make a similar decision. After spending perhaps many decades trying to stay alive, keep healthy, extend life - a time may come when it is wrong to fight death and right to allow oneself to die... to allow events take their fatal course.
How did Jesus know, how can we know, when it is right to allow ourselves to die?
After all, for Jesus, he was still young - just thirty-three - and presumably could have had many more years to preach and teach; and personally to lead the development of a church, built according to correct principles (if that was what he wanted).
Why then did he die at 33? The implicit reason given in the Fourth Gospel is that Jesus had completed his ministry with the resurrection of Lazarus.
It is a further question why it was necessary for Jesus to raise Lazarus. Many Christians believe that this miracle was not a resurrection; however, I believe that it was (and that we are told this in in the Fourth Gospel).
Therefore, apparently, it was necessary for Jesus personally to resurrect Lazarus in order that he would (after death and ascension) be able to offer the same to all Men. And this was precisely what Jesus came to do: offer resurrection to all Men.
A difference was that Lazarus was resurrected into his own corpse, and into this mortal earth. This was clearly a very important demonstration and teaching - but its cosmic significance was that Lazarus soon afterwards wrote the Fourth Gospel; which is our primary and most authoritative source on Jesus's mission and teaching.
(Presumably, this interpretation of Lazarus's resurrection suggests; the resulting Fourth Gospel is more than just another historical text, with the inevitable errors and deficits of transmission, copying, tampering and translating through many centuries. Presumably there exists the possibility of its being 'received' in a qualitatively special fashion - by the assistance of the Holy Ghost. So that its message may be directly-known in a way that transcends error and distortion... Such an explanation makes sense of the distinctive nature of Lazarus's resurrection.)
But, to return to the original question of "why did Jesus die when he did?" - this can now be understood as a more important question than the usual one of "why was Jesus crucified?"
It was necessary that Jesus died (that he allowed himself to die) when he did, but the method of death was only secondarily important.
In the Fourth Gospel we can read of Jesus meditating, praying, consulting with his Father about whether this was the 'time to die' (or, presumably, whether there was more he needed to do first) - and being assured that Now was the time.
To this, Jesus needed voluntarily to assent. He might in theory have resisted death for many decades longer, and done all sorts of other things... but Jesus agreed to allow death to happen Now, because his real earthly-work was finished; and it was time for his Heavenly work (as the Holy Ghost) to commence.