Military power is not enough to deter attacks: nation-states also need capability and will to be credible.
For instance, during the Cold War, neither the U.S. nor the USSR seriously threatened the use of nuclear weapons because the other side had enough nukes and the determination to retaliate.
Another example: the U.S. has the capability to carry out large-scale military operations anywhere in the world. Normally, this would give it credibility. However, in the early 2000s the American military was spread so thin because of heavy troop deployments in Iraq and Afghanistan that its capability and credibility were diminished. This is why Iran and North Korea defied the U.S. so cheerfully.
Whatever one’s opinion of the justification and morality of Israeli military responses to Palestinian attacks, it was long and clearly understood that Israel had the capability and will to retaliate if they were hit. In contrast, the 2006 Israeli invasion of Lebanon against Hizbollah and the 2014 attack on Gaza were not successful and diminished Israel’s credibility.
A country with a weak or poorly led, trained and equipped military has little deterrent credibility. For instance, despite its nuclear missiles, Russia’s previously huge and feared conventional forces lost capability and credibility after the collapse of the USSR led to severe cutbacks. However, Putin has since rebuilt the military. Its recent invasions of Georgia and Ukraine and using personnel and warplanes to support the genocidal government in Syria have restored Russia’s standing as a military power for the dark side. In addition, it has repeatedly used disinformation and other ‘active measures’ like compromat and cyberwar, plus economic pressure - cutting off gas supplies from their pipelines and demanding higher prices, imposing trade sanctions on Georgia, Ukraine and Belarus, etc.
Sometimes leadership simply lacks military will. For instance, after the mass slaughter of WWI, Britain and France did not resist German rearmament and expansion in the 1930s, instead trying to avoid war by appeasing Hitler.