A post on Facebook dated July 17 this year appears to explain how it is possible to enter Spanish territory in circumstances identical to those of Friday evening in Palma.
It says that entry into Spain could be possible on a flight from Casablanca to Istanbul, which was precisely the route of the Air Arabia Maroc flight that made the emergency landing at Son Sant Joan on Friday. It mentions "someone feeling unwell" during the flight and everything to be agreed by whom and how.
The police investigation in Palma includes trying to check social media accounts of the passengers who have so far been detained.