Termux gets killed easily, even if you set it to unrestricted in your battery-saving settings. Here is one of the mechanisms that causes Termux (and other apps) to be killed: https://github.com/agnostic-apollo/Android-Docs/blob/master/...
This module isn't affected by battery-saving mechanisms because it runs as a system process rather than an app process.
You can disable the phantom process killer in developer settings in Android 14.
Termux is rock solid on my Galaxy Fold 4 without any root or adb shenanigans.