Israeli Prime Minister Benjamin Netanyahu is locked in a contest that has largely centered on his handling of the Oct. 7, 2023, attack by Hamas and the protracted wars that have followed.