The wikitext snippet you posted appears to be seriously broken. More precisely: It is unbalanced. Technically, there is no such thing as "broken" wikitext. The parser will always output something (as he does in the example). However, this doesn't mean such wikitext is ok. Sure, nobody is stopping anyone from writing unbalanced code. But it becomes unpredictable (as the example shows), unreliable, and effectively unmaintainable as it starts to heavily depend on quirky internal details of the parsers implementation, how it approaches certain aspects, and in which order they are processed.
The bigger problem here is this: Even if you figure out how the parser works right now, it might change, as it already did many times. Have a look at pages like https://www.mediawiki.org/wiki/Markup_spec to get an idea of how complex this topic is, and how many people tried how many times to nail it down, all failing for one or the other reason. Code like the one you showed depends so much on the tiniest implementation detail of the parsing process, it becomes so fragile that it might break any day for reasons nobody could ever anticipate without a warning.
Please balance your wikitext.
Best Thiemo