This is actually addressed by the Israeli Military Law - a soldier MUST OBEY a “merely illegal” order (although (s)he SHOULD point out the presumed illegality to the commanding officer). A soldier MUST NOT OBEY a “clearly and obviously illegal order”.
OK, you ask, where is the line? Well, Israeli courts have in the past accepted that a “Clearly and Obviously illegal command” is (my paraphrase) “A command over which a black flag flys” - usually taken to mean a command that, if obeyed, will directly lead to the unnecessary loss of innocent life.
It’s obviously still a judgement call on part of the soldier. But there are guidelines, and they will be looked at by a court of law. Courtmartialling is not a hinderance to a soldier refusing a command, because there has been (to my knowledge) exactly ONE case of a soldier being executed by court-martial, and that was way back in the War of Independence (1948). No way it would happen in Israel, 2004
It is pertinent to note here that the few soldiers who refused to serve in the West Bank/Gaza actually constitute less than 1 percent of reservists called up for duty.
The world tends to focus on the dissenters, not the mainstream, but as you can see, they clearly constitute a minority.
What is also interesting is that the number of Israelis above the age of service who insisted on volunteering to protect Israel far exceeds those refusing to serve.
As far as what constitutes an illegal order, it is impressive to see the extent to which the Israeli Surpeme Court interferes with military matters. In most countries the Judiciary is loathe to interfere with the military, even in the US.
Take for example, the issue of torture, for which Israel is often condemned. In truth, Israel is one of the only countries to have expressly outlawed torture of any kind, including those types typically called “physical pressure” such as sleep deprivation or making the person stand for long stretches of time. This was done even with the full knowledge that using these techniques would without question save civilian lives from terrorist attacks. Note that the US army has been using these techniques in Guantanamo Bay on captives, even though there is obviously no direct threat of any kind to its populace.