I tried this in InDesign 2025 and found the following trap.
InDesign needs to reload the Submenu once to reflect ScriptMenuAction’s enabled in InDesign’s UI.
It seems that the appearance of enabled is reflected in the UI when the MenuItem is reloaded. For example, if it is reloaded by removing focus from InDesign and re-focusing it, or by clicking on the root Submenu of the ScriptMenuAction, it will look correct.
We need to remove surely the event listeners added to ScriptMenuAction before reloading the plugin/script.
Even if you rewrite the program content and reload it, the old event listeners will remain and work unless you remove them yourself or quit InDesign. That can cause unintended behavior.
It is especially easy to forget to remove them when reloading plugins in the Adobe UXP Developer Tools. Be careful.
Incidentally, I have withheld the plugin from the public because I could not achieve reliable removal of the menu. The report is here.