Bike cable housing come in two varieties, one of them is used for brakes and has an internal wound metal structure, usually, with an inner liner to reduce friction. If you'd strip the housing from its outermost layer, you'd find an spring like metal tube. You can stretch it and it would look like a tiny notebook binding spring.
The other variety, used for shifters has an structure comprised of many straight metal wires. These wires run parallel to the whole housing direction. It also has the liner inside. (I've never found shifter housing without it).
I'ts somewhat easy to confuse one for the other, as sometimes they can look almost the same but brake cable housing is a little bit larger in diameter, both externally and internally, as the corresponding cables are different too, the brake cable being thicker.
The brake housing structure can resist the higher compression force needed, but can change its effective length a little bit when it is bent, so, when you turn the handlebar to one side or the other, they effectively change length a tiny bit, which does not affect braking, but it is enough to throw a derailleur out of the precise alignment needed to keep the chain in the cog.
Something to have in mind is to also use the correct ferrules to terminate the shifter housing ends. The ferrules are necessary to keep the housing reinforcing wires from protruding out when subjected to pressure, particularly where the housing meets frame cable stops. I've have forgot to install ferrules os mistakenly used the wrong type, and precisely what happened is that the housing wires protruded from the sheath and jammed with the main cable in the frame stop hole.
Using the correct housing and proper ferrules fully inserted ensures the length of the housing remain the same, which keeps cable tension "stable" and that makes for more precise and predictable shifting.
When this length changes, cable tension tightens and/or loosens, which in extreme cases may produce involuntary shifts, something referred to as "ghost shifting". In less drastic cases, it causes difficult shifting and drivetrain noise that returns even after you fine tune the derailleur.