For Samsung devices like Galaxy S7 with Android 7.0 OS, a function called App power monitor is offered, which extends battery life by putting background apps to sleep.

App power monitor

App power monitor info

However, for apps optimized by App power monitor, their accessibility services (if any) will also be turned off when getting optimized.

Accessibility - Services

As a result, if you want any of your app have its accessibility service remained on, you need to select it in Unmonitored apps.