The sound bar is designed to be connected to your TV and turn on and off when your TV turns on and off.
Since most cable boxes never turn off, this will cause the bar to never turn off and not stay off if you turn it off with the remote. It's best if the bar is connected to the TV so it will turn on and off with the TV.
If you have the bar connected directly to a Smart TV with an optical cable and it is, seemingly, powering on by itself at random times, then it is likely an internet connection issue.
Smart TV's are constantly doing background maintenance and updates through the internet, even when the TV is powered off. This internet signal can cause the sound bar to power on, thinking that it is about to receive and output signal.
To resolve this, you may need to contact the TV manufacturer to file a bug report with them so they can possibly address this in a future update.