Sleep laughing is a common phenomenon known as hypnogely. Hypnogely indicates a mild disruption in sleep patterns during the REM state of sleep, but it is generally harmless.
The human sleep cycle is composed of multiple phases. REM sleep is the only phase of sleep in which dreaming and sleep laughing occurs. While the body releases hormones that keep it paralyzed during sleep to prevent self-injury, some people still manage to talk or laugh in response to their dreams. Someone who is laughing out loud during sleep is experiencing a reaction to their dream, and not reacting to anything in their surrounding environment.
An interesting facet of sleep laughter, as explained by Pub Facts, is that the dreams people have that cause them to laugh in their sleep are not necessarily always humorous. In fact, a study of ten people who experienced regular sleep laughter revealed that their dreams would have been troubling or disturbing to them in waking life. This may be evidence that laughter is used as a means of coping with unsettling material in the dream, which would suggest that hypnogely is a self-soothing mechanism like nail biting or self-stimulatory behaviors.