It should be safe to run CPhidget_delete any time after closing. The problem here is that the object probably is still in use during the detach handler.
If your program is expecting to connect to a lot of different Phidgets, you can try using the Phidget Manager to attach and detach the Phidgets. You should be able to safely call delete in the Manager detach event. If you're only ever expecting to be connected to one Phidget of that type at any given time, then you can safely reuse the handle since you don't have to worry about them piling up over time.
The other option is to upgrade to Phidget22 which handles this issue.