Hand flapping is a stimulating behavior. They call it a "stim" for short. A lot of the kids on the spectrum have a "stim" and hand-flapping is a quite common one. It can be a form of comfort as "bbnelson" stated.
Common forms of stimming among people with autism include hand flapping, body spinning or rocking, lining up or spinning toys or other objects, echolalia, perseveration, and repeating rote phrases.
There are many theories about the function of stimming, and the reasons for its increased incidence in autistic people. For hyposensitive people, it may provide needed nervous system arousal, releasing beta-endorphins. For hypersensitive people, it may provide a "norming" effect, allowing the person to control a specific part of their sensorium, and is thus a soothing behavior
Hope this is helpful.