When travelling in an international flight, you pass a border with passport check at both the departure and the arrival airports. It means you spend time in an international area. What are the applicable laws in this area? The one from the country the airport is located in? A special set of international laws? Are you juridically out of any country (as if in international waters)? Is there special status with flights between countries with special immigration agreements (e.g. Shengen area)?
There are three common situations:
- The country you are departing has outbound passport control
Once you cross the line you have officially left the country as far as immigration is concerned. You must pass through immigration to exit this area back to the public spaces.
In some cases, like Vancouver, it's not really "passport control". It's just a guy who checks your boarding pass and tells you that you cannot return this way (he has no authority other than calling someone else who does). But it's effectively the same thing. Canadian immigration gets passenger lists from the airlines and doesn't bother you on the way out.
- The country you are traveling to has remote pre-clearance. The USA does this from Canada and Shannon, Ireland.
Once you cross the line you have officially departed the current country and entered the destination country as far as immigration is concerned. You may travel directly to your destination, usually without any further interactions of any kind with immigration or airport security (rather dependent on the gate arrangements at transfer airports).
- The country you are departing does not have outbound passport control
Or at least not at this departure point.
You mix with other international and domestic travelers and board your departing vessel. You are considered to have departed when you pass the boarding gate.
Note the repeated use of "as far as immigration is concerned" and "considered to have departed". The departure lounge is not an embassy, it is still the sovereign soil of the departure country and if the local police want you for anything they will just walk in and grab you. If the American pre-clearance staff object they will be bluntly told to shut up and get out of the way or get arrested themselves for obstruction (pre-clearance staff are not diplomats).
In all the above cases, once you are "considered to have departed" you have met any immigration limits you may have. If you do this one minute before midnight on the day your visa expires you will not be considered to be overstaying. If your flight/ship/bus/train is cancelled you will usually get a short-term readmission as you did "leave" and the fact that you are still here is beyond your control. if immigration really wants you to leave you might even get a free hotel room for the night.
Flights in the Schengen zone are considered to be domestic flights - there is no passport control.
Tax easements (duty-free shopping) have more to do with your intentions than position within the airport. I've been to airports where the duty-free shops are in the public spaces. You show your boarding pass, buy what you want, and it's delivered to your departure gate (which also nicely bypasses security). If you don't have a suitable boarding pass you simply pay the tax-in price.
If the airport construction allows it (Heathrow for example) transiting passengers remain in the international area and have no interactions with immigration. This is purely a convenience and cost-saving measure. If you are wanted by the police for something serious they can and will arrest you in the international concourse. If, in this example, the UK does not wish to admit you for any reason you are fine here as you do not officially enter the UK. Passengers transiting between airports (Heathrow -> Gatwick happens a lot) DO require admission to the UK, which is occasionally denied. This means you go back to your departure point rather than your destination.
Legal rights of the departure country extend up to the time the airplane's wheels leave the ground (not sure about ships). If you punch out the cabin crew while taxiing to the runway, the local police will be called. Do it after takeoff and it's really the pilot's choice to return and land or fly to the destination - legal authority passes to the air carrier's country of registration after takeoff but the pilot can choose to accept the local authorities rather than carry a problem for 10 hours.
If the departure country's authorities decide they want to invite you in for tea and biscuits after takeoff, they can request that the airplane return or land at another airport in the same country. If the pilot refuses they either let you go or shoot the plane down.
You may have passed a border check, but that doesn't mean you've left the country (just as at land borders: there's a gap between the border posts, but that land is still in one country or the other). So the laws of the country apply. Of course, there are usually some special laws or exceptions that apply to such areas, with respect to immigration and taxes.
The accepted answer provides many useful details but fails to make a very basic point: The laws of the country you are in do apply fully. Except in some very specific cases (e.g. there is a treaty between France, Switzerland and possibly Germany regarding Basel airport), an airport is entirely and unambiguously under the jurisdiction of the country where it's located and therefore subject to its legal system (including EU law in the EU).
Now, some special rules (e.g. regarding taxes and customs duties, immigration, search and seizure, etc.) might apply but those derive from the laws of the country in question, not from some sort of over-arching international rules that would supersede local law.
For example, you might be able to transit without a visa if you don't leave the international transit area, thus being exempted from the regular entry requirement. But the exemption itself results from local law, it's because the airport is in a given country that this rule exists, not in spite of it.
Is there special status with flights between countries with special immigration agreements (e.g. Shengen area)?
Let me answer this first: If you fly from one Schengen country to another, you won't pass a passport control. So the so called "Schengen area" at airports, where intra-Schengen flights depart (not to confuse with "The Schengen area") is not "international" in any way.
But even "international area" at airports is not "international" in the sense of "lawless". Neither will dissidents be able to safely travel through international airports of their home country, for example.
There are special agreements for international air traffic, most notably the Chicago Convention, but AFAIK they do not include the right to transit at every international airport in the world at your will.
Most notably, if you fly for example KLM from Edinburgh via Amsterdam to Chicago, Dutch authorities can and will call you out in Schiphol "international area" if they have any open speeding tickets on your name in their system. Unless you come and pay upfront, you and your luggage won't be allowed to continue the journey.