Kodi expects the audio hardware configuration to remain static so it will not dynamically switch between two different configs although you could probably detect an HDMI event to run a python script to make changes over the XML API. Also, on most laptop/generic audio chipsets the alsa configuration will just output sound on all devices; and to change that you'd need to dig into the configuration for that specific chipset and come up with a custom audio routing configuration. It's all technically possible but alsa expertise is one of the Linux "dark arts" and you're unlikely to find willing volunteers and a nicely typed-up howto.
Kodi on Windows probably handles this scenario better.