Solution
In order to change the EtherCAT slave state we need to change the Scan Engine mode to Configuration and then proceed with the slave states. When the scan engine is already in Active Mode, it is not possible to change the EtherCAT slave state.
The screenshot below represents a VI that programmatically changes the EtherCAT slave states.
In addition to the VI above, we need to change the Scan Engine state programmatically as shown in the screenshot below: