Christian Jarrett in BBC Science Focus, tells us it has a healthy purpose.
The most obvious function of emotional displays like laughter and crying is to signal to others what we’re feeling. But the fact that we laugh when we’re nervous shows this isn’t the whole story. Sometimes our emotional displays can be a way to mask our true emotions. If we’ve done something embarrassing, for example, we might laugh to cover up our feelings of shame or shyness.
Nervous laughter could also be a way to help us regulate our emotions. We usually feel more relaxed after we laugh, so a nervous chuckle when we’re feeling socially anxious can help to alleviate some of those negative emotions.