There was no international border between Israel and the West Bank in 1967. This was explicitly agreed upon at the Arab’s insistence in the text of the 1949 armistice agreement. There was only a temporary line between Israel and the territory that the Jordanians had occupied in 1948. The Jordanians violated the armistice agreement beginning with the shelling of west Jerusalem. The Israelis would have preferred not to have to fight on a third front, and requested that the Jordanians stay out of the conflict, but the Jordanians joined the fight anyway and were subsequently crushed and expelled.
Many countries have recognized the so-called green line as an international border (or the basis of future negotiations) for their own purposes, but neither the Israelis nor the Palestinians have ever considered it to be a border. I don’t believe there is any precedent in international law that allows external parties to unilaterally impose a border without the consent of either of the parties in a conflict. Therefore, talk of legality is mostly sophistry, and an attempt to interpret a situation according to pre-existing international law that never anticipated said situation. The Jordanians had no legal claim to any territory that Israel occupied in 1967, nor had the Palestinians made any claim to it at that time. In fact, the Palestinians had explicitly disavowed any claim to the West Bank in writing, and did not declare independence until 1988.
By the logic that Israeli settlements built on territory captured in 1967 are illegal, many Israeli cities within the internationally recognized borders of Israel should likewise be considered illegal, because in both cases they are built upon former Ottoman public lands within the British Mandate of Palestine which were taken by force. This in fact the position that countries that do not recognize Israel take. The West’s (for lack of a better term) position is essentially that territory taken by force in 1948 and 1949 is legitimately Israeli whereas territory taken by force in 1967 is not, even if it had been the personal property of Jews who were ethnically cleansed from the areas occupied by invading Arab powers. There isn’t really anything morally or legally consistent about that.
That aside, the Israeli occupation (but not annexation) of the West Bank is unambiguously legal. It was agreed upon by both sides under the terms of the Oslo Agreement. The Israeli occupation (but not annexation) of the Golan Heights is unambiguously legal because Israel and Syria remain at war. It was also captured in a defensive war.