Why does a flash freeze a picture even if I use a shutter speed like 1/10 sec?
I don't understand it, because the light will hit the sensor the whole time, not just when the flash is fired.
The key here is how much light will be hitting sensor during flash, and how much during the rest of exposure. The sensor does gather light during the whole exposure; all of it is blended into one static image.
In case the ambient light is much lower, it won't have nearly as much effect on the total light that reaches the sensor, and therefore only surfaces lit by flash will stand out.
On the other hand, if the sensor gathers illumination provided by ambient light in similar or even higher amount than illumination caused by flash, it will show in the resulting image.
Combining areas lit by flash and areas lit by continuous light is most notably used for slow-sync technique. Example by Robin, 1/10 seconds:
To capture ambient light in addition to flash, you'll need to change the ratio between them. You could reduce flash power and/or increase ambient light (stronger lighting or longer shutter time). Note that changes in aperture or ISO would affect both kinds of light similarly, i.e. they don't affect ratio.
If you take a photo at 1/10 second without flash and the image is black, you have effectively "killed the ambient" with your shutter speed, the shutter duration is too fast (with your other settings) to allow enough light to hit your sensor to make an image. When you add flash, the flash duration is very, VERY fast, 1/1000 of a second or faster (depending on the flash model). So there is a very short burst of light from your flash to the subject and then to your sensor. The shot will come out the same at 1/10, or 1/60, or 1/200, up to the "sync speed" of your camera shutter. However, your settings may NOT effectively kill the ambient at all 3 shutter speeds. Often by the time you have slowed down your shutter to 1/10 you will start to have ambient light building up during the exposure duration resulting in an ambient-lit image on your sensor, in addition to the flash-lit image produced by the flash burst.
In medium ambient lighted action photography situations you can end up with motion blur (ambient) plus flash lit, and if you use "second curtain sync" camera setting the blur moves into the flash lit image, which can be an interesting effect.
In dim ambient light action photography, your subject can be moving fast enough that they don't "register" on the sensor in an ambient light only image, and only the flash lit view of your subject will show in the image. Again, you can take a test ambient-only shot and find that your fast moving subject doesn't show at all on a slow shutter shot (e.g. a 20 second exposure) and you just get the background ambient. Then add a flash and your subject suddenly appears!
(Aside: If you increase your shutter past the camera sync speed you will only get part of the image because not all of the shutter will be open at the moment of the flash of light. Read up on "sync speed" and "high speed sync" if you want to know more about that.)
A great site for learning about flash photography is Strobist. Read the lighting 101 and 102 entries.
You're right, there are situations when flash won't freeze the action. It all depends on the relative levels of the ambient and flash illumination.
If the majority of the light is coming from the ambient lighting, you'll still see motion blur with a slow shutter speed, because most of the light in the scene will NOT be coming from the flash.
However, if the ambient light is at very low levels vs. the flash (or is non-existent and the subject is only lit with the flash), then motion blur won't register in the scene. A typical hotshoe flash, used at its highest power level is liable to be in the range of 1/1000s. At lower power levels, it will be even faster. (See: How does the power of a flash relate to the duration of the flash pulse?) Often your flash pulse will be much faster than your maximum shutter speed.