When statement is not working

Then perhaps you need a must statement, not a when statement.

    must "/ios:native/voice/service[type=‘voip’]/shutdown = 'true'" {
      error-message "Cannot configure/unconfigure the CLI when VoIP"
                    + " services are running or when active VoIP calls are"
                    + " present";
    }

…although your error message text suggests that you are validating the state change, not the data. If so, must or when statements will not help. You will need a tailf:validate statement and callback application code for that.