What Is International Law?
Your assumptions that someone is or isn't "illegally occupying" territory, or that something is or is not illegal under international law, isn't really how international law works. Likewise, it is not, in general, possible to apply principles of international law to a dispute to determine if something is or is not legal under international law in the manner that you usually can in the case of ordinary domestic law, or sometimes can in the case of treaties as applied to non-state persons (e.g. international tax agreements or treaties applicable to diplomats).
International law involving disputes between sovereign states, unlike most kinds of law, isn't something that gets resolved definitively by a tribunal in most cases. International law isn't even really something that compels countries to act in a particular way even though they consider it as one factor among others in the course of figuring out what they are comfortable doing in their foreign and military affairs.
There are some principles that one considers, but they aren't binding in any legally meaningful way that can be enforced through court action against an existing and operating sovereign state, except to the extent that these principles are enforced by the domestic courts of the country alleged to have violated international law.
Equally importantly, international law also doesn't balance disputes in the abstract. Unlike a question of domestic law, it does not follow that the same conclusion will be reached in every case with analogous facts. The entire history of the dealings between Israel, Iran, Syria and anyone else who might consider intervening in the situation is never divorced from the abstract legal issues that someone might say is presented by a set of facts.
International law is a collection of justifications for military and diplomatic action or inaction, rather than something with a true "legal" character in the conventional sense.
In international law, each country judges its own case, and inconsistent interpretations of the facts are routine.
Some General Principles Of International Law
Generally speaking, when one sovereign state controls territory and another sovereign state tries to use military force in that territory, the subject of that military force will feel justified to use all necessary means of military force to counterattack the country using military force. International law recognizes the right of sovereign states to take measures to defend themselves against hostile enemies.
Generally speaking, in a genuine military conflict between nations, it is not considered a war crime to target a military installation that is used by "combatants" in a conflict (as opposed to civilians or hospitals for the wounded, for example).
It is often considered more legitimate for a country to take military action against another country that is authorized a UN Security Council resolution than it is to do so without that authority, and it is considered more legitimate for a country to take action against a country whose actions have been condemned by the UN Security Council (without an actual authorization to take military force) than it is to do so without such a determination.
As a general rule, the use of military force to resolve territorial disputes that haven't arisen "imminently" (i.e. hours or days or weeks or maybe even a few months ago), is frowned upon, and the more less imminent the threat, the more problematic intervention becomes. Once territorial control is a fait accompli and an international war isn't in continuing progress since before that happened, the use of military force to resolve territorial disputes is strongly frowned upon.
A key part of the analysis is the legitimacy of the claims to the territory. As a general rule, third party military intervention within territory controlled by another state or de facto state is considered much more acceptable if it is done with the permission of the state or de facto state that controls the territory, or by the state or de facto state that claims the territory, or in conjunction with the military forces of the state or de facto state that claims the territory.
It is not normally considered proper under international law principles to unilaterally militarily "liberate" territory under control of another sovereign state, without the endorsement and military involvement of a legitimate claimant to that territory (outside the context of an ongoing international war that has been in progress since the imminent aftermath of the legitimate claimant's loss of control, and even then, conferral with a government in exile and local insurgents is expected). A third party country that uses force in territory controlled by another sovereign state, without the express or implied consent of a sovereign state with a legitimate claim to that territory, is an illegal aggressor under international law, rather than a participant in a collective security effort which international law recognizes as a legitimate reason to use military force.
This principle, however, is subject to an emerging exception to allow military intervention by a third-party sovereign state to prevent or interrupt a domestic genocide in another sovereign state. There has also long been another exception for third-party use of force to proportionately punish violations of treaties to which both countries involved are parties even if the third-party has no direct stake in the conflict as a form of collective security.
International law recognizes conquest during a war as one of the legitimate ways by which a sovereign state may acquire territory from another sovereign state. But, international law prefers situations where territory obtained by conquest is recognized by a subsequent international treaty acknowledging this reality.
Some Relevant Facts
Like any case where someone is asked to consider international law, you begin with an analysis of the particular players in the conflict and the history of the dispute, because these questions don't have answers in the abstract.
The territory that you mention, Israeli occupied Joulan a.k.a. the Golan Heights, was seized from Syria during the Six Day War with Israel in 1967, and annexed by Israel in accordance with its domestic law in 1981 (37 years ago).
Israel has been uninterrupted control of the Golan Heights since 1967, and has successfully resisted multiple military efforts to retake this territory.
There has not been a continuous international war under way between Syria and Israel since 1967. While Syria and Israel have not resolved this territorial dispute via a treaty, Syria and Israel were parties to a disengagement agreement after the October War of 1973, similar to the armistice reached between North Korea and South Korea at the end of the Korean War that didn't actually declare an end to that war.
Iran does not now, and never has had, a claim in its own right to the Joulan a.k.a. the Golan Heights.
Syria has been dispossessed of this territory for more than 50 years. Its dispossession was not imminent.
The direct successor to the regime that used to be the universally recognized legitimate regime in Syria, i.e. the Assad regime, is not universally recognized as the legitimate government of Syria and does not control all of the pre-civil war territory of Syria.
I can't tell from the information available to me (perhaps someone else can provide an answer or comment), who controls the area from which the Iranian strike was made, or if it was made with Syria's direction or approval. If Syria's involvement was too pro-active, it might have violated its 1973 treaty with Israel.
Historically, at a minimum, Syria has not objected to Iranian sponsored military action directed at Israel from its territory. Also, the Assad regime has received some support in the Syrian Civil War from Iran, so it is fair to characterize Iran and the Assad regime as allies. So, it is fair to assume that the Assad regime does not really object to Iran's most recent actions directed at Israel in the Golan Heights.
On the other hand, the Assad regime does not appear to have involved its own military forces in this strike by Iran on Israeli forces, or in many of the other actions taken by Iran supported forces against Israel. The Assad regime does not itself appear to see its Golan Heights territorial dispute with Israel as a priority given its existential interest in a favorable resolution of the Syrian Civil War in its favor.
None of Israel's allies would consider the Iranian strike on the Golan Heights to be legitimate. Probably, neither would Saudi Arabia, although this is colored by the fact that Saudi Arabia and Iran are leaders of opposed geopolitical factions in the Middle East.
Israel, under whose law the Golan Heights are part of the sovereign territory of Israel following a legal annexation, not only considers the Iranian strikes to be acts of war against it, but does not consider its control of the Golan Heights to be an illegal occupation.
The U.S. does not recognize the annexation of the Golan Heights by Israel as legal, but also does not accept that military action to restore that territory to Syria (let alone a Syrian regime that it does not recognize as the legitimate government of Syria) is legitimate or justified. Indeed, the U.S. has condemned Iran as a state supporter of terrorism, in part, a consequence of its support for groups that have used force against Israel, in previous acts similar to this one.
In Iran's view, it probably sees its actions as legitimate for reasons along the lines of the way that the original question here is formulated, although this is not a terribly righteous and clear conclusion. Moreover, as far as Iran is concerned, the details of the status of the Golan Heights are irrelevant, because it believes that Israel has no right to exist at all and that any military actions directed at Israel at any time for any reason, is therefore justified.