Ancient Japanese samurai, in the war battle, their hair was often scattered for various reasons. At this time, the hair in the middle and front of the head will cover the face, block the line of sight and affect the battle. So some samurai shaved off the hair in the middle and in front of their heads, so that even if the hair was scattered in battle, it just hung freely on both sides of their heads and backs, which would not affect their eyesight. Because of the obvious effect, samurai followed suit and became an unwritten tradition over time, but this hairstyle was limited to the samurai class.
References:
Baidu Encyclopedia: The First Generation of the Moon