It's similar to saying:
* "Don't get your knickers in a twist"
* "Chill out"
* "Take it easy"
The origin of the phrase is unclear, but it might refer to the idea that someone might pull their hair out in frustration, so telling them to "keep their hair on" is a way to stop them from doing that.