the context menu is global, so you only want to run it once per page load. I don't know which framework you're using, but you could be seeing that if the code gets loaded more than once. The workspace existing (I don't know where that variable comes from in your code) is not itself relevant but having the condition may ensure it only runs once, in your particular case.
Alternatively you can:
a) call `getItem` first (also described in the above documentation). if the item isn't registered this function will return null. if so, don't try to unregister it.
b) wrap in a try/catch and do nothing in the catch -- that just means it's already been unregistered so you don't need to do anything else.
Best,
Maribeth