How in the fuck does the shading get this fucked up when I change the topology a little bit?

How do I fix it?
Can you point me to some resources on how to fix such shading problems based on topology?

The shading always makes me feel like I'm just throwing the dice.