JERUSALEM — In 2009, when Benjamin Netanyahu returned to power for a second run as Israel’s prime minister, a job he has held almost continuously since, he was confronted with a major change in the region: Hamas, a militant Islamist group, had been elected to power in the Gaza Strip three years earlier.