The "rule" is broken in those instances because the chords under the melody are moving towards D minor, which is why you start seeing E-naturals, F-naturals, and C-sharps. In the first two bars (which are solidly in G minor), the solo part only uses F-sharpsI just looked at first few bars of Eccles 11 sonata, which is a classical student piece. Seems to me that the melodic minor rule is breached as often as it is kept. See for yourself:
View attachment 5102784
(sorry for the ugly Win+Shift+S adjustment)
To me it's actually very interesting question to think about. Knowing a rule, does it help create something, or does it stand in a way?
Regarding the original post, the way it was explained to me in music school was that for pure harmonic resolution, the strongest resolutions are the half-step movement from b6>5 and 7>1 (and 2>b3, but that's not really relevant here), which is why in minor our cadential figures are iv (or iimin7b5) > V7 > i. When building harmonies (and staying in one key), composers tend towards harmonic minor as the default so that you have both the b6 and 7 at your disposal. When creating melodies you still want to emphasize that harmonic movement sometimes, but having that augmented second in the scale is really jarring. In this situation, if you have a melody that is emphasizing a 7>1 resolution you want to use 6 instead of b6 because that leads towards 7>1; if you have a melody that is emphasizing b6>5, you use b7 instead of 7 because b7 leads towards b6>5.
Hope this makes sense!