The United Nations’ top court said Friday that Israel’s presence in the West Bank and East Jerusalem is illegal, in an unprecedented opinion that called on Israel to end its decades-long occupation of territories that Palestinians want as part of a future state.