Flutter happens when the eigenfrequencies of two oscillations move close together so their motions can reinforce themselves mutually. When that happens, then the amplitude will increase with each oscillation, up to a point where the amplitude is big enough to break things. That is how bridges are destroyed: Ever more energy is accumulated in the structure, a tiny bit with every oscillation, until the total overwhelms the strength of the weakest part.
If the two eigenfrequencies are not close enough together, both motions will still exist but will normally be damped so they die down quickly after being excited, e.g. by a gust. A typical example is the wing bending motion: When the aircraft flies into an updraft, the wingtips flex up, elastic energy is accumulated and set free once the extra lift from the updraft dies down. The wingtips move down and will very briefly oscillate around their long-term vertical position.
Now add a free-flying aileron (mechanical control system with stick free). This also can oscillate around its long-term deflection angle. As long as the eigenfrequencies of both motions are sufficiently apart, they will not interact. This should be ensured throughout the normal flight envelope. However, flying faster will increase the aileron eigenfrequency, and in this case we should focus on the first antimetric bending motion of the wing. At one point the aileron frequency will come close to the wing bending eigenfrequency, and only then this particular flutter mode will happen.
The glider in the second picture of your question is the SB-9, a longer-span version of the SB-8 (which itself is flutter-free). The added span moved the wing eigenfrequencies down, so they met with the aileron frequency at a lower speed. Now flutter could be observed when flying at the right speed, but it could be stopped simply by gripping the stick.
Therefore, the possible protections against flutter are:
- Limit the flight envelope. Prohibit flight speeds at which flutter is possible.
- Increase damping. This can be as simple as adding some friction. The rudder cables in gliders are run in PE tubes which add some friction, eliminating rudder flutter.
- Put mass balance on all control surfaces. On the Handley-Page O/100 bomber of 1916 it was enough to crosslink the two halves of the elevator, which stopped the first known case of flutter in airplanes.
- Increase eigenfrequencies by increasing stiffness. In the SB-13 flying wing glider high modulus carbon fiber was used in the spar to shift the wing's eigenfrequency sufficiently up to avoid a coupling of the wing bending mode with the short period mode of the airplane
- Increase eigenfrequencies by mass reduction: When a wing is made lighter especially towards the tips, e.g. by clipping the wing tips, its eigenfrequency will move up, shifting flutter speeds up. Conversely, by adding wingspan to the sound SB-8 design, the eigenfrequency of the SB-9 wing went down.
- Change eigenmodes: By running the aileron pushrods near the wing shell, wing bending can effect an aileron deflection which helps to dampen the wing's bending mode.
- Cross-coupling of eigenmodes: By reducing the wing spar sweep of the SB-13 by 3° relative to that of the whole wing, the bending motion causes wing torsion which reduces incidence when the wingtips are bent up and vice versa. This is similar to the pushrod trick and is an application of aeroelastic tailoring.
In a similar way, the forward location of the engines on an airliner wing creates an inertial torsion moment when the wing flexes. This increases damping, so this example could had equally appeared in the first point.
To ensure a design is free of flutter, a range of tests is performed prior to first flight and during flight testing. From this answer:
Since maybe fifty years every new design must go through a static
vibration test to check which elastic eigenfrequencies exist.
Analytical methods are used to predict the (speed dependent)
aerodynamic frequencies and the structure must be modified to remove
any possibility of resonance. Next, the airframe is tested in flight
at ever increasing speeds and with exciters at the tips of all
surfaces (those can be like the vibration motor in your smartphone,
only bigger, or, in the simplest of cases, the pilot moves the control
surfaces). At increasing speeds, the exciters are run through a
frequency sweep (typically from 5 to 60 Hz) and the resulting
amplitude is measured by strain gages or accelerometers.