So this really depends on whether you're in a hosted space (Jcink, ProBoards, Zetaboards, IPS Cloud, XF Cloud, Circle) or you're in some form of self-hosted space (everyone else where you have some kind of hosting)
In the former case your best hope is that you learn about it before it happens and have some opportunity to get a database backup - Jcink offers you this, and you can absolutely migrate users + content to another setup using this. Other platforms vary.
In the latter case, this is where it gets interesting. Especially because this is a real situation that some people are debating. In any case, in the self host area, there are two broad situations you can talk about - the open source and the not open source/mostly pay to play communities.
Self host + open source
This is your phpBB, MyBB, YaBB, YaBB SE, SMF, PunBB, FluxBB, Wedge, XMB, MiniBB, Flarum etc etc arena. More than one of these platforms (and this is by no means comprehensive a list) already had what we could call a death (though it may have had a jump start later) - you always have two options: take over maintenance yourself, or migrate to something else. Taking over maintenance yourself is not trivial and you have a deep dark pit of unknowns with respect to hidden vulnerabilities in the underlying code, not to mention that the maintenance burden is quite something if you're not really used to it.
Closures of these platforms have happened - YaBB SE is a prime example; it stopped being developed in 2003 when all dev effort went to SMF to build something from scratch, though it was absolutely done with the mindset of bringing users along from YaBB SE, and a lot of effort was sunk into making that as least painful as possible, even down to porting the default theme from YaBB SE over to SMF and bundling it as a theme for years.
The key takeaway is that you own your data, and you can get at everything so you certainly have choices about handing it over to someone or getting someone to help you do a migration to something else. Different platforms are more or less good at doing this.
Self host + closed source (whether pay to play or not)
So, this is your vBulletin, IPS, XenForo, Woltlab situation. But it also potentially includes software that isn't open source, where taking it over isn't an option. It's still on your server infrastructure so you still have all the data, content etc.
In some cases - vBulletin, XF I believe, though I could be wrong - the licence would theoretically permit you to modify the software to keep it running in the event of a shutdown and no further patches from the developers. In the case of vBulletin, this is a real consideration since vB 3.x and 4.x are no longer supporting most recent PHP versions - they cap out at PHP 7.1, so your choices are: stay on unsupported versions and hope no vulnerabilities are found; stay on unsupported versions and try to find + patch vulnerabilties yourself; move to something else.
As you have the data, you can plug this into something else, and make that migration - and there are resources in most cases to help you do it. If you're coming from a fringe software, there's always the option of a custom migration - it's not usually that hard to jangle it together.
What I do foresee, and what was recently argued at great length and anger elsewhere, is whether Invision Community/IPS shelves their self-hosted edition. They have committed to it for the next couple of years, but they admit it is a shrinking proportion of their revenue, it has a significantly higher cost to support than the cloud edition and that realistically at some point it might disappear. This will mean anyone self-hosting on IPS Suite will have to think about a migration either to another platform, or to the cloud (with quite a cost implication; pricing starts at $89/month for all but the basic IPS forum package, and anyone seriously staying will want the CMS module, I think, so they're in the $89/month camp immediately)
Migrating to the cloud of course comes with a loss of control - there are things you just can't do with it (like conveniently running a WordPress front end to the forum on the same server as one example), though for many this isn't the headache this sounds like.
tl:dr; if your platform closes, you've usually got options for how you deal with that which can see you take your community somewhere else and give it a new home to continue. Some of these require more or less work and more or less cost financially or practically - but there are always options.