Wouldn’t the drag caused by the flaps just decrease the acceleration, so, although they can lift off at a lower speed, wouldn’t it be faster to just use no flaps and rotate at the higher speed that is required?
Increasing the flaps does increase the drag, but not by that much initially. For the first stages of flaps you gain more by reducing required takeoff speed. If you would increase the flaps more and more, eventually the drag would become too much and you would lose takeoff distance again.
Flap setting has an affect on the wing’s lift coefficient and on the aerodynamic drag. Increasing flap angle increases the lift coefficient, and therefore reduces stalling speed and the required takeoff speed (the same lift will be created at smaller air speed due to greater lift coefficient). This reduces the takeoff distance. In the same time increased flap angle increases drag, reduces acceleration, and increases the takeoff distance.
The net effect is that takeoff distance will decrease with increase of flap angle initially, but above a certain flap angle the takeoff distance will increase again. An optimum takeoff setting can be determined for each type of aircraft and any deviation from this setting will give an increase in the takeoff distance.
The flap setting also affects the climb gradient. Increasing the flap angle increases the drag, and so reduces the climb gradient for a given aircraft mass. If there are obstacles to be considered in the takeoff flight path, the flap setting that gives the shortest takeoff distance may not give the required climb gradient for obstacle clearance.
Note that the climb gradient is also affected:
More flaps allows taking off from shorter runways, but reduces obstacle clearance capabilities.
Because without flaps extended there is less safety margin for stalling in the landing.
Picture above from this answer shows the lift coefficient as function of the angle of attack. With flaps extended, a certain amount of lift is reached at a lower AoA than without flaps.
It is a safety feature during landing, when speed needs to be reduced as much as possible. Not so much during take-off, and TO flaps setting is often not fully deployed. But deploying them does reduce TO distance since the same lift can be reached at a lower speed.
Wouldn't it be better to use no flaps, and rotate at the higher speed that is required?
Well, now we are talking about a short field take off. If you ever watched Lindbergh's takeoff the day of the famous journey across the Atlantic non-stop flight, barely clearing a power line on climb out, or even actually done one off a muddy or snowy runway, you know the answer to this question.
Many take-offs are done with flaps up because an aircraft will produce more lift per given amount of thrust (drag) " clean ". Key to this is reaching the speed where the wing can be set to its optimal Lift to Drag ratio AOA and also be going fast enough to produce adequate lift.
Cambering up a wing makes it a better lifter, giving the ability to get the plane off the ground at a lower speed, but at the expense of more drag (read thrust and drag interchangably).
Notice the same effect can be achieved by increasing the coefficient of lift of an unflapped wing by raising the AOA past optimal L/D ratio, but the risk is, especially with wings that stall at a lower AOA, the power on stall!
So if the runway is covered with take-off roll drag producing items such as mud or snow, or simply is not long enough to reach flaps up takeoff speed, we use some flaps and slats to get airborne and climbing as soon as possible.
Once airborne, it is generally best to retract flaps and climb out Vy, unless that obstacle needs to be cleared, then we use the less efficient Vx.
Increasing camber (and AOA) does increase amount of lift at a given speed, but will require a proportionally greater amount of thrust. A bigger or turbocharged engine helps here, along with careful monitoring of airspeed.