While that might be the intent, in practice it becomes an annoyance that just forces you to die in several situations. Usualy when you press a button, you expect the action that button is bound to to activate, and your brain is literally not wired to expect things to just not do anything because you happened to get hit by some dude right after you switched weapons.
As it stands, this does indeed punish people for poor positioning. It also punishes people for getting randomly hit by a javelin or arrow when trying to switch to a melee weapon to defend themselves from incomming melee combatants, punishes people who get surprise atacked from behind (took too long to switch to melee? Your oponent's attack just canceled your switch), and is ultimately an annoyance by sometimes rendering helpless agains melee combatants if you happen to misjudge a weapon's range and switch too late. It's also a incredibly lame way to die. Numerous times have I been facing some melee enemy while holding a ranged weapon, switched to a melee weapon, got hit by some other enemy / ranged weapon / random horseman / etc, and just gave the enemy a free kill out of sheer confusion on why my blocks were not working.
While I see your argument, if that was indeed the dev's intention, the mechanic is just a terrible way to go about doing that.