Okay. To clarify. It is a must to go through customs and immigration through air.
The procedures in air aren’t the same as on the ground. As far as I’m concerned (nearly 100% positive), a passport and proper visa documentation is needed when passing all borders. Let’s take an example.
I’m a passenger on a British flight from Gilbraltar to Madrid. I must go through immigration upon arrival in Madrid due to Gilbraltar being a British territory.
Now, it is possible to go through another country’s immigration before even getting on the flight to that country. Here’s another common example of this.
British flies their Speedbird 1 service from London City to New York’s John F. Kennedy. Due to weight constraints in EGLC, they have to stop to refuel. They choose to stop in Shannon for a specific reason. Shannon Airport in Ireland has U.S. immigration and customs. Upon arrival in JFK’s Terminal 7, the passengers head straight to baggage claim, pass customs, and they are out of the airport.