There is a way to (sort of) accomplish this with python scripting, but it's probably not as clean as you would hope and personally I would not recommend it.
You can change between preset themes in a python script by loading in the presets directly from your install path, something like this:
bpy.ops.script.execute_preset(
filepath="C:\\Program Files\\Blender Foundation\\Blender 2.91\\2.91\\scripts\\presets\\interface_theme\\blender_dark.xml",
menu_idname="USERPREF_MT_interface_theme_presets")
And you can check which mode you're currently in with the read-only bpy.context.mode
property. This will be 'OBJECT'
for object mode and one of several 'EDIT_*'
values for edit mode. You can check the Python API Docs for a full list of these values.
The hard part is then determining when to execute this script. As far as I'm aware, Blender does not provide a way to register callbacks for modal changes. This essentially leaves two options:
Change your keyboard shortcut(s) (the Tab key by default) to execute your script rather than change modes, and have your script change modes with:
bpy.ops.object.mode_set(mode='EDIT') # or 'OBJECT' for object mode
There are several downsides to this, such as that your script still won't execute when you change modes with the interface (dropdown in the top left or the pie menu), and you lose Blender's prediction of what mode you want to enter (based on what mode you're in, previous mode changes, etc.)
You can leave your script always running in the background, searching for mode changes in a loop and changing the theme when it detects one. This is not only incredibly ugly and inefficient, but will also make you lose the respect of any reputable programmer.
Personally, my recommendation would be to just develop the habit of either checking what mode you're in by glancing in the top left, or guaranteeing it using the pie menu (Ctrl+Tab). The latter takes a fraction of a second once you get the hang of it.