Israel's decades-long occupation of the Palestinian territories is illegal and needs to end "as rapidly as possible", the UN's top court said Friday.