Can top level domains disappear if countries cease to exist / malfunction?

Solution 1:

Yes, top level domains disappear:

.zr is the former Internet country code top-level domain (ccTLD) for Zaire. When Zaire was renamed to Democratic Republic of the Congo in 1997, .zr was phased out and .cd took its place. In 2001, .zr was deleted.1

Source: https://en.wikipedia.org/wiki/.zr

Additionally you might lose the right to renew:

On 29 March 2018, as a consequence of the United Kingdom's exit from the European Union, it was announced that "as of the withdrawal date, undertakings and organisations that are established in the United Kingdom but not in the EU, and natural persons who reside in the United Kingdom will no longer be eligible to register .eu domain names or, if they are .eu registrants, to renew .eu domain names registered before the withdrawal date".

Source: https://en.wikipedia.org/wiki/.eu

Or the price might be increased significantly:

The TLDs seeing the biggest price hikes are .hosting and .juegos (Spanish for “games”) which are going up from about $20 retail and about $10 retail respectively to about $300 apiece. [...] Names in .audio, .blackfriday, .diet, .flowers, hiphop .guitars and .property, currently priced in the $10 to $25 range, will all start retailing for about $100 per year.

Source: http://domainincite.com/21603-schilling-big-price-increases-needed-to-keep-new-gtlds-alive and the user Coburn who was able to provide a source.

As for stability of a western European country vs south american countries: Hard to say. The last two world wars weren't that long ago and were 'centered' in Europe, so who knows where the next 'round' of country and border destabilizing war will be. Also worth noting that QR codes as a way to share hyperlinks won't stay relevant forever either, imagine right now if someone had a tattoo of a usenet group. Point of all of this together is: URLs (and QR codes as a way to encode them) aren't meant in any way to be permanent.

Solution 2:

All domains are ultimately controlled by the Internet Corporation for Assigned Names and Numbers (ICANN).

From Wikipedia:

ICANN is an American multistakeholder group and nonprofit organization responsible for coordinating the maintenance and procedures of several databases related to the namespaces and numerical spaces of the Internet, ensuring the network's stable and secure operation

They assign the registries for Top Level Domains, including the countries. They let the countries decide who their registries are.

In short, nothing is permanent. Countries, registries, or even tattoos.