Do you want to switch between two icons, or do you have more than that?
If it's just two icons, you can set the default and an alternate icon in the configuration of the scriptable menubar item:
Then you can just use the "Alternate Color Regex" to activate the alternate icon & colors:
If you need more icons you need to return them either by providing the icon_path, a base64 encoded string containing the icon (icon_data) or the sf_symbols_name in an escaped JSON:
return "{\"text\":\"testTitle\",
\"sf_symbol_name\":\"house\"}"