It called a "Non-Inertial Frame of Reference."
Because (almost) everything in the universe is accelerating, you see imaginary forces popping up everywhere.
In this particular case, the moon moves in some path, the flag resists that motion because of its natural inertia.
Thats one explanation.
More likely the flag appearing to wave is caused by the impulse imparted by electromagnetic waves and subatomic particles. But thats more complicated stuff.
and we are not headed into the sun -_-
It wouldnt make sense to someone who hasn't studied physics raven. Im studying it in university, I know what im talking about. Riz put it better though, I was too lazy to say that.
In simpler terms:
Since the astronaut propelled the flag into the ground, causing the flag to move slightly in a wave pattern, the flag acted as if it were under the influence of wind. Since the force of gravity on the moon is 1/6th (i think) that of the earth, and since it is perpendicular to the motion of the flag, it stayed in the wave formation for a long period of time. Newtons first law says that an object in motion will stay in motion till an external force acts against it, and that force on the moon is small