How to connect to select/deselect event?
I'm not going to claim this is the correct way; but it will work
import bpy


@bpy.app.handlers.persistent
def _depsgraph_update(scene):
    print(bpy.context.selected_objects)


bpy.app.handlers.depsgraph_update_post.append(_depsgraph_update)
# bpy.app.handlers.depsgraph_update_post.remove(_depsgraph_update)

The other thing you can try; is listening for the active object changing - on the basis that you can't select without changing the active object.  Note you won't get a change notification on undo
bpy.msgbus.subscribe_rna(
     key=(bpy.types.LayerObjects, &quot;active&quot;),
     owner=object(),
     args=tuple(),
     notify=callback,
)