To support undo, your command must make a copy of either the geometry or the object’s attributes, attached the user data to the copy, and then call either ObjectTable.ReplaceObject or ObjectTable.ModifyAttributes.
Here is a sample:
https://github.com/mcneel/rhino-developer-samples/tree/master/rhinocommon/cs/SampleCsUserData
– Dale