There are two explanations.
(1) In the film shots you can see the astronauts rotating the flagpole as they push it into the ground. This rotation causes the flag to wave backwards and forwards. In a couple of shots, the flag continues to move after the astronaut has left the frame.
(2) In still photos such as the one below, the flag appears to be fluttering but it is not. The flag is stationary - it is simply wrinkled. This wrinkling was caused by the way the flag was packaged for flight. You can actually see this flag in other photos with exactly the same wrinkle pattern - proving that it is not moving at all.
In some missions there was an additional factor - the astronauts could not fully extend the horizontal crossbar (at the top of the flag). This further exaggerated the wrinkle effect.
Next Page: Inconsistent Backgrounds