Is it possible to change this setting using termux?
I initially asked this question to figure out a bug-fix for an open-source app but it turns out it's in AOSP (see here if you're interested to learn it, https://github.com/MuntashirAkon/AppManager/issues/388)
Now, for Users who want to apply this setting to a batch of apps the best and easy method would be to use this app, https://github.com/MuntashirAkon/AppManager
From AM's prevent background operation option available in the batch operations.
There are should be many alternative apps such as https://github.com/mirfatif/PermissionManagerX and App Ops which you can try and see what it offers.
This answer didn't cover how you can do it using CLI but you can check the comment by Irfan Latif if that's any help.