To settle the full weight of the aircraft on the runway which enhances drag, friction, and brake performance. In simple terms, to stop faster.
Flaps allow the aircraft to fly at slower speeds without stalling by increasing lift by increasing the area of the wing. So in landing they are used to be able to continue to fly the plan as slow as possibly safe so that you can land as slow as possible. This then allows the plane to touch down without the danger of snapping of the gear and/or control issues (ie sliding of the runway, cartwheeling down the runway).
Once the plan is on the runway (front gear too), then there is no need for the flaps, and they are retracted to settle the airplane on to the runway. Since clean (no flaps), the speed required to fly is higher than when they are extended.
During take off, they are always set to some degree, but they allow the plane to fly at a slower speed allowing the plane to use less runway or even take off within the confines of the runway.
They are also extended for short take offs and landings. Same reasons as above.
When the wing is clean, it is most efficient, and this allows the plane to fly faster.