How do I make Illustrator not change the gradient's position and size when I change the path's shape?
Essentially you don't. Gradient fills are based on the boundaries of the shape they are applied to. If you alter the boundaries, then the gradient position and length will change. It is simply how gradient fills work.
It's a very simple matter to grab the Gradient Tool and move the annotator to where you want it.