Im watching "Ran" and i notice it, and I have seen many paintings depicting this.
By shaving do you mean chonmage haircut?
It originated from the Warring States period (prior to the establishment of Tokugawa shogunate in 16th century). Originally it was for simple reason: such haircut makes it easier for soldiers to hold helmet. After the war ended, Tokugawa shogunate established, and samurai became the ruling class, such haircut became a status symbol for samurais. It persisted for generations, even had its own edict that requires all samurais to wear such haircut, until the Meiji government abolished the edict in 1871.
Matsunosuke Nishiyama's Edo Culture: Daily Life and Diversions in Urban Japan briefly touched this subject, if I recall correctly.