My final verdict after lots of debugging: The problem isn't related to MariaDB in the end. PHP-FPM is consuming too much RAM, which results in OOM killing MariaDB. Sorry about the confusion, all of my previous assumptions were mostly guesses, because I couldn't confirm anything, nor reproduce the issue. Today, I stayed up later because it seems that night hours for me are peak hours for FreeFlarum traffic. Memory usage was high. I restarted PHP-FPM, which freed almost all of it. Culprit found.
This is likely because of how many extensions FreeFlarum has, and/or how some large forums generate too much traffic. This isn't surprising, since hosting forums with thousands of posts on a free service is expected to cause issues at one point. Forums that are this big require their own server at this point, as it is impossible to put them together into 8 GB of RAM.
We have a couple of options:
1) Allocate/buy more RAM (unlikely, as I wonder whether that might be financially sustainable for a longer period of time)
2) Modify PHP-FPM configuration of every forum to limit RAM usage (will require an automated script)
3) Politely ask owners of big forums to migrate elsewhere (probably the most reliable solution)
First I'll try whether option 2) makes anything better. If not, I'll go for 3). As for tonight, OOM will probably happen again during peak hours. I have adjusted our script for PHP-FPM restart to also restart MariaDB, if our main forum is unreachable. Hopefully this will serve as a temporary solution, until tomorrow.