I think I figured it out. The hero being left behind should have one stack, and the hero being dismissed should have only one unit. Select the single unit and "split" it into an empty slot of the second hero. In the split window that opens, click on the number 1 and the arrow to the right, then close the window.
It works in the mod; they fixed that particular issue, which was present in the original game.
Hmm... I tried it, but it didn't work.
I know one way; I had a similar situation in the game a long time ago... Basically, take a hero, for example, with 1 gnome, attack someone... in battle, summon spirits, kill the gnome, then the spirits kill everyone, and when only the last stack of neutrals remains, resurrect the gnome (BUT! earth magic must be basic, or the hero must have no earth magic at all)... the spirits finish off the stack of neutrals, and the hero remains without an army:) ... but you can't attack anyone with such a hero))
Стримы и обучение тут:
https://www.youtube.com/channel/UCWlnXU5R5RLCMuWzIpBc65Q