This idea is inspired by D&D based CRPGs.
If a unit is engaged in melee and wants to move away, the opponent gets a free melee attack out-of-turn.
This does not apply to a second or third unit engaged in melee, only the initial ones.
That will make it more expensive and dangerous for ranged units to move away and make protecting and positioning them well a priority for a player. Especially when they are equipped with sniper and assault rifles.