Imagine Countries G, O, and Y all border Country S.
Now imagine the following chain of events:
- Years prior, Country S had declared that closing a certain maritime access corridor to that country would be considered a declaration of war.
- Countries G and Y sign a mutual defense agreement.
- In response to a (false) report that Country S was amassing military forces along Country Y's border, Country G begins amassing their military on the G/S border, and takes up positions overlooking the aforementioned maritime access corridor.
- Country S reiterates their declaration that closure of said corridor would be considered an act of war.
- Country G closes said corridor to Country S's shipping.
- Countries G and O sign a defense pact.
- Country O begins their own military build-up.
- Fearing their ability to withstand a war on two fronts, Country S launches a preemptive strike against Country G.
- Country O begins attacking Country S.
- Country S defeats Country O's attacks, and captures territory from them.
Now, the war as a whole is, strictly-speaking, an offensive war initiated by Country S against Country G. However, since Country O then initiated hostilities of their own against Country S, to whom does the territory that Country O lost to Country S legitimately belong according to international law?