How does retracting flaps help extend the glide of an aircraft?
Some answers presume that raising flaps reduces lift.

That is wrong.*

All it does is to increase angle of attack, until the change in flap setting is so severe that the airplane stalls. Only then will the airplane lose lift. With a smaller flap setting, the pitch trim changes and the airplane pitches up a little to keep lift constant. If the (auto)pilot does not correct the pitch trim for the new flap setting, the airplane will settle at a new, higher speed. Here, however, we can be sure that the autopilot kept speed constant (it only disengaged at 150 ft, and then the copilot took over. He certainly did not dive to pick up speed at this altitude!).

Raising the flaps does, however, reduce drag. See below for the A320; with a B777 the result will not be all too different.



A320 polar with 3 different flap settings (picture source)

Assume the airplane flies at a lift coefficient of 1.2 with flaps at 35°. Raising them to the next setting of 22.5° will move the operating point horizontally forward to the 22.5°-polar curve. Here the airplane flies at the same lift, but a smaller drag coefficient.

Retracting the flaps completely will not allow it to stay at this lift coefficient because the baseline polar stops below a lift coefficient of 0.9. The airplane will stall and needs to accelerate to keep flying. Only then will the airplane have to pick up speed.

I remember two occasions where that happened to me and raising the flaps saved my butt:


Landing in a field that turned out to be an asparagus field on short final. Ugh! Poor preparation - from higher up the field looked fine, even and smooth without vegetation. Coming closer I saw the rows of earth under which the asparagus grows (see here for a picture how this looks). Flying an ASW-20C and with flaps on "L", I changed them back to "4" and made a 90° turn to a different, adjacent field. I had played with the flaps at altitude before, so I knew that switching between "L" and "4" does not affect altitude.
Landing the SB-8 on an unfamiliar airfield that sits on a hill. Landing against the wind means I fly trough the leeward side of the hill during approach, but I did not keep some margin for the downdraft but started final at an altitude appropriate for a normal airfield without downdraft. I quickly noticed what was going on and switched the flaps from +8° back to 0° without changing speed and also retracted the wheel again. I just made it. When I climbed out of the airplane, someone came closer with a big grin and revealed to me that just a week before another pilot (who was as unfamiliar with the airfield as I was) had landed his glider into the bushes which mark the airfield perimeter. Of course, I also had tried out the effect of different flap settings at altitude when getting familiar with the SB-8.




* Since this statement raises blood pressure in others, let me explain. I only posted here after one answer after the next repeated this meme. Now some authors have edited and improved their answer. Would that had happened without clear words? Judge for yourself.

Now to the issue of lift loss: When the flaps move up (slowly), the lift force decreases just a tiny bit. The aircraft starts to sink, which immediately raises the angle of attack and puts an end to any further lift loss. Liftforce is immediately restored to its old value. That is why I simplified this process and said there is no lift loss, because there effectively isn't.

Next, the change in pitching moments from flap movement lets the aircraft pitch down unless pilot or autopilot retrim for the new flap setting. This is a much slower process because it involves a rotation of the airplane and its lengthwise acceleration.