Could a civilian fly directly from a belligerent country to a neutral one surrounded by the other side (for example from UK to Sweden or, or from Germany to Ireland)? Or was a detour via Portugal or Spain necessary? Or was civilian air traffic completely shut down?
There definitely was some amount of civilian air traffic that fits your description, albeit not risk free, there are a fair amount of instances where 'civilian' aircraft were shot down. Obviously no direct air traffic between belligerent countries, but for sure from belligerent countries to neutral countries as you point out. There was a route between Stockholm in neutral Sweden and Perth, Leuchars in the UK dubbed the 'Ball-Bearing Run', which mainly transported cargo, but also some 6000 passengers flew this route. It was operated by military crew in de-militarized aircraft with civilian BOAC markings. Niels Bohr for instance was flown out of Stockholm aboard a 'civilian' De Havilland Mosquito. Was this route open to everyone? Given the nature of this operation probably only people deemed important enough to the war effort.
BOAC Cooperated with the Dutch carrier KLM (of which a portion of aircraft and crew managed to flee from the Netherlands on May 10th 1940) on the London-Lisbon route. This route was a proper civilian air route, although Lisbon was watched closely by both sides as both had spies there. And Lufthansa flew to Lisbon as well. On June 1st 1943 the KLM lost a DC-3 PH-ALI / G-AGBB "Ibis" operating BOAC Flight 777 on this route, as it was shot down by the Luftwaffe. Al crew and passengers were killed. Amongst the Passengers was Leslie Howard. From Dutch aircrew memoirs I know that attacks happened more often on this route. In April 1943 K.D. Parmentier (Head of KLM flight ops, and Pilot of DC-2 "Uiver" in the London Melbourne race) managed to lose German fighters in a cloud on the same route.
BOAC operated a Route to Egypt, Cairo via a massive detour as well, although I'm pretty sure it was suspended during the German occupation there.
Additionally Lufthansa Continued to operate routes to: Switzerland (Berlin - Zürich / Dübendorf), Lisbon ,Istanbul.
These are as far as I'm aware all 'civilian' routes that more or less tick the boxes set out in your question.
I highly doubt that a civilian from one side would be able to travel by air / detour to the enemy side without being found out.
i.e.: I highly doubt anyone flew with Lufthansa from Berlin to Lisbon, and then managed to board a BOAC/KLM flight to London.
However, the Lisbon and Stockholm routes were sometimes successfully used to retrieve shot-down aircrews, whom somehow managed to get there.
Civilian travel was highly regulated during WWII Crossing internal borders in occupied Germany was only possible when you had the right paperwork, and control was fairly tight.
Sources
Flight International Sep 27 1945, p.350 https://www.flightglobal.com/pdfarchive/view/1945/1945%20-%201929.html
Capt. D. Watson, BRITISH OVERSEAS AIRWAYS CORPORATION 1940 – 1950 AND ITS LEGACY, Journal of Aeronautical History, (2013 No.3) https://www.aerosociety.com/media/4844/british-overseas-airways-corporation-1940-1950-and-its-legacy.pdf
Hans-Liudger Dienel & Martin Schiefelbusch, German Commercial Air Transport until 1945, Revue belge de philologie et d'histoire, vol 78 no. 3-4 (2000) https://www.persee.fr/docAsPDF/rbph_0035-0818_2000_num_78_3_4472.pdf
Dutch archival source material I came across during my own research.
Yes, there were civilian flights between belligerent countries and neutrals, even those surrounded by their opposition. This answer will focus mainly on flights from Britain made by British airlines.
In the immediate pre-war period, there were two main British airlines. British Airways had been founded in 1936, as a merger of several older airlines. It ran mainly short-haul services to European destinations. Imperial Airways had been running since 1924, and, as the name suggest, was responsible for longer-distance routes, especially to far-flung regions of the British Empire, though it also flew some European routes. While the two airlines were commercial rivals, the threat of war following the Munich Crisis of 1938 brought some collaboration. The two airlines agreed to, in the event of war, move their operations to airports at Exeter and Whitchurch, near Bristol, for landplanes, and Falmouth or Poole for seaplanes. These bases were judged to be safer from air attack in the event of war. The airlines would focus on transporting supplies for the RAF (which did not, at the time, have its own transports), carrying VIPs, and airmail, in that order. Meanwhile, the Cadman Enquiry, sparked by poor labour relations within Imperial Airways, was investigating the operations of the two airlines. The report of this enquiry was used to justify a plan to nationalise the two airlines and combine them into a single organisation, though war would start before this plan could be realised.
On the 29th August 1939, with war imminent, the British Government began to enact restrictions on air travel. All private flying was forbidden, and many civilian airfields brought under military control. Britain's domestic and international airlines were effectively nationalised, under the banner of National Air Communications. However, flights to Britain's allies and neutral powers continued much as they had pre-war. As in the original plans, planes were moved to safer airports. Five main routes were flown to European destinations during this period. Flights to Scandinavia departed Perth in Scotland, and flew to Stockholm via Stavanger and Oslo in Norway. Direct flights were flown to Paris and Bordeaux from Whitchurch and Croydon. Flights to Bordeaux would proceed to Lisbon directly, or to Cairo via Marseilles, Tunis, Malta and Sollum. Seaplanes would fly from Falmouth to Biscarosse, near Bordeaux, then to Bracciano and Brindisi in Italy, followed by Athens, Suda Bay on Crete, and Alexandria, which served as the starting point for flights to India, Australia and South Africa. Finally, there were also flights to Ireland, with some stopping there, and some trans-Atlantic flights using Foynes in Ireland as a refuelling stop. In November 1939, Imperial and British Airways were officially combined to form the British Overseas Airways Corporation (BOAC), though it would not operate as such until the 1st April 1940.
The beginning of operations by BOAC would be soon followed by the end of the Phoney War. Three BOAC aircraft were lost during the German invasion of Norway. Weeks later, the Germans invaded France, leading to the end of BOAC services to Paris on the 11th June 1940. One BOAC aircraft was lost at Paris' Le Bourget airport during the invasion, and another was lost in an air raid on the UK. Flights to Africa through France continued until the 28th June, when Vichy France banned BOAC aircraft from their airspace. The Italian entry to the war brought an end to direct flights through the Mediterranean. Despite these challenges, BOAC continued to operate.
Flights to Stockholm were run directly from Perth, using Lockheed 14s. This service was brought to an end in October 1940, but there was a real need for such flights to continue. Stockholm was a useful place to gather intelligence, and Swedish ball-bearings and machine parts were in short supply in Britain. As such, the service re-opened in March 1941, using Hudson IIIs and Whitleys converted from RAF service. The Swedish airline ABA also used the route, which led to some friction when the British end of the route was moved to the RAF base at Leuchars. There were considerable risks to this route, as it meant flying over German-held territory, which could be well-defended. Most aircraft flew at night, but this could be difficult over the summer, with its short nights. To allow the route to continue operating, RAF Mosquito light bombers were transferred to BOAC, starting in December 1942. These aircraft were mostly used to carry ball bearings, but could carry passengers. This was a difficult, dangerous, uncomfortable journey. The Mosquito carried a single passenger, lying on a mattress in the bomb bay, and wearing full flying gear, including oxygen mask, intercom and flying helmet. Despite all the precautions, and the use of these high-performance aircraft, ten aircraft were lost on the Stockholm route during the war. Even so, some 6,000 passengers and 500,000 pounds of freight were carried between Britain and Sweden.
The banning of BOAC aircraft from airspace in Vichy France and French North Africa meant that BOAC aircraft had to find new routes to Britain's African colonies. This was especially difficult as many of its longest-ranged aircraft had been requisitioned for RAF use. To this end, BOAC began a seaplane route from England to Lagos via Lisbon, Bathurst (now Banjul) and Freetown. This then linked up with a landplane service across the continent to Cairo. This was one route that could be used to visit Lisbon. Direct flights to Lisbon were also run from Poole, carrying passengers and airmail. These often used aircraft and crews from the Dutch airline KLM, who had fled to Britain following the fall of Holland. From April 1942, these were open to not just VIPs, but also to fare-paying passengers. These routes ran out over the Bay of Biscay, avoiding French and German airspace. While it was safer than the Stockholm route, there were still risks. From 1943, the Allies began to intensify air anti-submarine patrols in the Bay of Biscay; several aircraft on BOAC routes were shot down by Luftwaffe aircraft hunting for Allied ASW aircraft as a result. This included the 1944 shootdown of BOAC Flight 777 with actor Leslie Howard aboard. This lead to the route being flown at night until Allied troops could clear the west coast of France. In October 1944, a weekly flight to Madrid was also begun.
Flights to Ireland were typically run to link up with BOAC's transatlantic service. Run using Boeing 314 flying boats, this had two routes. In summer, it ran from Baltimore to Botwood in Newfoundland, and then to Foynes. In winter, Botwood was closed. Instead, the flights travelled from Baltimore to Bermuda, then to the Azores and Lisbon, before reaching Foynes. The return route added in an extra leg; instead of flying by the Azores, the route went to Bathurst, Lagos, Belem in Brazil, and Trinidad, before going to Bermuda. From Foynes, passengers could use a BOAC shuttle to Whitchurch to reach the UK. Initially, the shuttle was run using seaplanes, but after Shannon airport became available, there was a shift to landplanes, freeing up seaplanes for longer routes.