While watching, and eventually learning to just switch my brain off when it came to narrative, it struck me that there were two options: either the art form had originally evolved to not need a cohesive plot (and perhaps even an deliberately nonsensical plot - it seems like it would have been easier to write something vaguely logical), or that the original audience would have understood it much differently that I did. Or a third option?
Opera history student here, and the first thing I want to say that the question itself that you're asking is a little misleading, because it implies that The Magic Flute is a typical opera. It isn't. The Magic Flute is considered quite unusual in its plot, even for the operas of the time.
Opera originated around 1600 with a group of Italian composers who took Greek drama as their inspiration. Early operas tended to use classical mythology as their sources, and modeled their storytelling after Greek plays. The earliest opera we know of is Jacopo Peri's Dafne (around 1597-98), but most of the music is lost. The earliest extant opera we know of is Peri's Euridice (1600). Both of these operas have libretti (texts) by Ottavio Rinuccini. The earliest operas which are still somewhat well-known and/or frequently performed are Montiverdi's, including L'Orfeo (Orpheus), Il Ritorno D'Ulisse (The Return Of Odysseus), and L'Incoronazione Di Poppea (The Coronation Of Poppea). This last one was not based on a myth, but on an actual person, the wife of the Emperor Nero. But it is still a classical source, and for a long time, most operas were based on classical mythology, mythologized history, and later, medieval and more contemporary renaissance sources. Many composers and librettists wrote operas based on the same sources, and often, different composers would set the exact same libretto to music. It was also not uncommon for productions of operas to cut-and-paste different settings of the same text together. The exact conventions of operatic storytelling shifted over time, and while some of the stories may seem weird to us today (think of how many Greek myths have crazy bizarre things happening in them), at the time these were the convention. The stories likely would have been familiar to the audience ahead of time, and a lot of the stories are still familiar to us today. Now, the style of storytelling is pretty alien to us today, but at the time that was just the convention.
In the 18th century, opera seria became the convention, the most important figure of which was librettist Pietro Metastasio, who sort of codified the form. A lot of the environment of early opera stayed the same. Still largely classical sources or similar, still multiple composers would set the same story or the same text, still productions would mix-and-match. But the style shifted, and became more cohesive across the board, often even formulaic, so you could count on most Metastasian opera seria looking pretty similar to each other. These were the days when operas were popular, and composers and librettists would churn them out as fast as possible.
At the same time, opera buffa was happening, which took its cues more from commedia dell'arte. Most operas produced in this century fit squarely into one of these boxes, or one of some similar subgenres that also became conventional. La Partenope, which seems to have been an original plot by librettist Silvio Stampiglia, was one plot which was set by many composers (most notably Handel) that did blur the line between comic and serious, but structurally, it fits best the mold of opera seria, which just happens to have some comic elements to the plot.
The next important figure was Cristoph Willibald Gluck, who made an active choice to sort of minimalize opera, which he thought had become too bloated with virtuosic showpieces and reduntant da capo arias. In very brief, opera started out as a musical experiment based on Greek drama, then it became a fort of musical entertainment, and Gluck wanted to place the emphasis back on the drama. Gluck also used primarily classical sources, with his best-known operas being based on the myth of Orpheus, Iphigenia, Alcestis, and so on. Again, these are generally well-known myths that were the source of many operas before Gluck, and would be the source of many operas to come, so the story itself isn't the innovative part. It's the storytelling.
Which brings us to Mozart. Most of Mozart's early operas fit squarely in the conventions of opera seria, opera buffa, or some other subgenre that was still conventional, such as the German singspiel, which is stylistically distinct from opera buffa, but tends to deal with similar sorts of plots. His last five operas are a bit more interesting. He wrote three operas with librettist Lorenzo Da Ponte, the first of which, The Marriage Of Figaro, (based on Pierre Beaumarchais' play of the same name) is considered to be possibly the first opera where the lower-class characters are the protagonists. It is a farce about two servants of Count Almaviva who are going to get married, and need to foil the Count's plot to sleep with the bride. It is a sort of screwball comedy, and a lot of the basic comic tropes are things we still recognize today. The plot is complex, because it's a farce, but it is not "weird" to conceive of. What is notable is that the plot was both contemporary, and new.
The second opera Mozart and Da Ponte wrote together was Don Giovanni, which is considered an opera buffa, but does significantly blur the lines between comic and serious. It is based on the Don Juan legend, which is an old story, but like The Marriage Of Figaro, the opera was modern in style. It also does play with class. The protagonist (who is also the villain -- villain protagonist; pretty new for opera) is an evil aristocrat, and his servant Leporello is a more sympathetic comic character. The heroic characters who oppose him are a mix of aristocrats and peasants who team up. As with The Marriage Of Figaro, the plot is complex, but with the exception of the ghost scene, not really "weird."
They also wrote Cosi Fan Tutte which isn't really as relevant here. Its literally merits are oft debated, but for the purposes of analyzing the plot -- that is, the strict events that happen -- it's a fairly conventional mix of comic opera tropes.
Which brings us to The Magic Flute (1791), which doesn't have a single identifiable source, and it seems Emmanuel Schikaneder, the librettist, drew on many different sources and stitched together a pretty original opera. What is generally brought up is that Schikaneder and Mozart were both freemasons, and the opera is loaded with masonic imagery. Which is a rich theme for analysis, but doesn't really adress the main points of the plot, which really are pretty bizarre, and the opera also has a lot more supernatural elements than other operas of the day. The opera was a success, but the opera was also an anomaly, and there are no other operas quite like it from that era.
Around the same time, Mozart was also working on La Clemenza Di Tito, which was adapted from a libretto by our old friend Metastasio. La Clemenza Di Tito is really interesting because the libretto is a very old-fashioned opera seria libretto, but the music and the style is more moder, and it creates an interesting contrast with The Magic Flute. Two operas, by the same composer, from around the same time, one of which is incredibly new and modern and unusual, and the other of which is almost a nostalgic throwback to an old-fashioned style.
I guess the point I'm making here is that by the end of Mozart's career, the sorts of plots which could be successful in opera had really begun to diversify, and as we get into the 19th century, opera really splinters off into all sorts of different styles. Opera seria on classical themes mostly went out the window, but there continued to be commedia-style comic operas, alongside dramatic operas based on the works of contemporary authors like Walter Scott or Friedrich Schiller. Toward the end of the 19th century, verismo became a thing, and some composers like Mascagni and Puccini took interest in more realistic plots, in contemporary settings with realistic characters. The most famous of these is La Boheme. Still other more modern-leaning composers and librettists wrote operas in more modern dramatic styles such as surrealism. One composer who practically ran the gamut was Richard Strauss, whose subjects included classical mythology (Elektra), traditional opera buffa (Die Schweigsame Frau), grand epics (Die Frau Ohne Schatten), bittersweet romance (Der Rosenkavalier), absurdism (Ariadne Auf Naxos), and even a meta-opera discussing the conventions of opera (Capriccio).
Ultimately, opera is just another form of storytelling, and the styles of storytelling, and the types of stories they tell, vary widely. What is popular at a given moment changes frequently, and the sorts of opera plots that are popular change over time, but the form is so varied that you could probably find an opera to match any dramatic or literary genre you cared to name. And The Magic Flute is an outlier.
EDIT: If you want some relatively easy-to-digest but still informative reading about The Magic Flute, I recommend Daniel Heartz's book Mozart's Operas, which covers seven of Mozart's most notable operas, including The Magic Flute. Mary Hunter's Mozart's Operas: A Companion is also a pretty friendly resource. For more reading about opera as a whole, Abbate and Paker's A History Of Opera is a pretty comprehensive and easy-to-find book, which focuses more on the texts of operas than the music, which is more relevant to this question.