This makes complete sense. The Darkness spell has a verbal component and they would hear you casting it.
AI can't measure preparedness. They don't know if they're capable of fighting you to the death or not; you have the advantage of having been in that exact same situation before. Changing the way they act is less likely to change gameplay surrounding dungeons (people will always find a way to defeat the computer, after all, it has relatively few options short of difficulty walls) than changing AI compositions.
Also, making AI walk out of AOE spells would arguably make them weaker, because they'd have to prioritise it over fighting to have any effect, which means they are essentially disarmed and giving you a +2 AB (possibly provoking AoOs) until they escape the AOE. If it is not prioritised, only one will fight you in the Darkness at a time, because you have no other input for the flow chart than, "Am I being attacked?" which means they'll all flee except the one you are hitting. The catch 22 for them is that they're less likely to escape it than defeat you by simply swarming you and fighting back in almost every situation. Some enemies have been given True Seeing to counter this spell specifically.
There's no perfect way to balance it, short of giving the AI more casters to counter your control spells with their own. Archers in the Curst caverns were implemented partially to diversify enemy roles in this way to make solo characters or less versatile parties a bit more pressured, though obviously that is one change out of many that would be required to make all adventures more challenging, varied, and unpredictable.