This usually happens when you're too close to your opponent. Let me explain:
From what I see, you already visualize the imaginary line that connects you and your target, and sometimes extends past them. This is the key here. Always keep this line in mind.
- When you're far away, no matter how the target moves, the shift in your path is gonna be small, because they'd have to move a long distance to the side to shift your angle significantly.
- However when you're closer, and especially within melee range, the smallest shift in your relative positions dramatically alters your path. So, when you're sitting on top of the enemy, the slightest movement to the side from either of you can shoot you on an unpredictable path.
Usually you don't dash through the enemy when you already are in melee range. When you just wanna gap close, you're far enough away so that it's controlled -- this usually happens when you first dash through a minion to land on top of them, then use E on them when you're too close. The dash is not 100% controlled even on minions. You can get it to land you on top of the enemy, but "on top of the enemy" can actually be a very vague thing and mean any position, including right behind them. So, when you E them, you can get flung towards anywhere.
There is a way to control it: if you watch Bjergsen and other high-skill Yasuos, you will notice that, when they want to dash in a straight line through minions that are not positioned in a straight line, they always click a bit backwards right after dashing, to adjust their angle relative to the next target. Then they dash.
They do the same thing when harassing champions -- sometimes they need to dash to them to get in range, but other times they reach them by dashing to a minion, in which case they sometimes run behind the enemy champion and dash back to safety.