Specifically in the case of Battle for Wesnoth, removing it would make attacking much, much more powerful and safer than it currently is. Currently attacking from a disadvantageous position isn't just low-yield, it can be genuinely harmful. It also gives ranged/melee specialists a fairly universal downside, in that they can be assaulted with relative impunity by anything with the attack mode they (credibly) lack.
It's probably worth noting that with how swingy, lengthy, and brutal Wesnoth combat is, each individual attack indeed appears to be its own mini-battle, rather than a simple application of damage.
Specifically in Age of Wonders, it's probably to make flyers' impunity a lot less absolute, get some of that mini-battle going, and help tie into the Movement Point system. I find it interesting how it lets powerful units get more attacks in on weaker ones than it could otherwise, but that it doesn't last forever and does eat up their available MP for next round, giving them less say in who they get to target with said attacks.
More generally, I think the rationale varies. Probably in some cases its just an immersion/style thing, where it "makes more sense" or "seems cooler" that units will tangle with each other instead of one running up and bopping the other on the head. In a lot of cases it's probably a more mechanical version of that, trying to add some gravity and cost to (some kinds of) attacking. In some cases it might be to punish trying to use a critically wounded/glass cannon to wail on things in safety, while in others it could be to reward using convincing finishing blows to avoid retaliation. In the more specialized cases, it may be a chance to let units specialize offensively in being attacked, or in attempting to discourage aggressors (though I'm not sure I've ever actually seen this example).