Maybe your character always faces towards where your velocity vector points, rather than the last key you pressed, so if you try to dash while you have some momentum in the air and mistime it (like pressing both at the same time but the dash first) you'll end up dashing in the wrong direction
Imo one solution would be to remember for a short time the last directional input, another would be to disable the dash if you're not pressing anything
This is just speculation though this may not be how it works idk