TLDs require actual work to operate (I say this as someone responsible for running 46 TLDs). They won't just keep operating indefinitely absent an actual team responsible for running them.
I'm a programmer at the Swedish Internet foundation which runs (or in industry terms: is the registry for) the .se and .nu (nuie) ccTLDs.
Basically we are a big old database. When someone registers a new domain, via a registrar, they send us that information (most commonly via a protocol called EPP). So we get "this is the domain, registered by this person, it has these hosts, it is registered for this long, with these DS posts, for example. Different registrys have different rules, for example the .se domain has a set of allowed characters that you are allowed to use in your domain name, and rules on how long into the future a domain can be registered for.
This data is then used to perform our most important job as a registry. Creating the zone file for our TLDs so that people could actually reach the domains.
That is from the technical side. There's also a big support side with different aspects. There are abuse issues that need to be taken care of, ICANN has a dispute mechanism that people are involved in.
Someone else already mentioned some of the technical aspects, but there are large customer support / contract / business relationship aspects too. You're maintaining business relationships with dozens of registrars, easily over a hundred. You're running a B2B-focused business with a large number of customers and there's random nonsense that's constantly coming up requiring human attention.
I figured it wasn't effortless to run, but they're adding new TLDs all the time like .ninja, .wow, .xyz and are up to over 1500 different TLDs. Compared to creating a random new TLD, is keeping .tw around really such a burden if there are many websites already using it?
It may not be. But for country level TLDs a company or organization actually manages the DNS server software - it may run "in the cloud" or not - but someone still have to mange that software and the host it runs on. (In addition to enforcing the policies and payments associated with that TLD.)
gTLDs are not ccTLDs, though. The gTLDs all run under the same standardized contract / set of rules, and if you're already running 1 then it's pretty easy to scale that to running N.
ccTLDs though are much more like special snowflakes though. There's a large difference in policies, features, technical implementations, etc., from one ccTLD to another.