select the object state in the Layers panel. You can only do that with an active state.
With select I mean you have to have a selection on the page. A colored dot right to the object state must show up in the Layers panel like you can see it below in my screenshot from my German InDesign where I selected the active state of an MSO (Multistate Object) with name "Status 1":
// Type the new name between the straight quotes
// using a text editor without formatting the text:
"My new name";
How to copy code to a script file, install the script file so that it is visible in the Scripts panel of InDesign and how to execute the script from the Scripts panel see e.g. here: https://www.indiscripts.com/pages/help#hd0sb2
The result after running the code above, ths object state is still selected, but the name has changed:
Or use Rob Day's script code in this post which has a UI for the renaming process of a selected element on the page: