Staying out of prison is a powerful motivator. Even more so when you’re a ethno-supremecist, genocidal sociopath with no moral compass or soul.
Everything Netanyahu does is to further his own political objectives. He wants to keep the life expectancy of his government going as long as possible because he would lose decisively if elections were held today. So he believes that painting a picture of “Everyone is against us, Israel vs. the world,” is in his own selfish, narrow interests.
And if he were out of power, he’d likely be headed to jail.
Netanyahu needs the war to survive politically, he needs Hamas, all the society’s polarisation, the state propaganda, etc.
He also knows that once he is out of the government he is probably going to be jailed too.