The Fifth Head
Brahma had five heads. The story of why he had five and why he now has four exists in several forms, but the most widely known in Shaiva tradition involves Brahma's pride in the moment of creation.
Brahma had created Saraswati, the goddess of wisdom, from his own being. Then, overtaken by an inappropriate attachment, he had grown extra heads to keep her in sight no matter which direction she moved.
One version says the fifth head declared: "I am the creator. I am above Vishnu. I am above all."
Shiva, hearing this, incarnated as the terrifying form Bhairava — wild, naked, with wild hair and a terrible weapon — and with his fingernail, severed Brahma's fifth head.
The Brahmanicide
The severed head stuck to Bhairava's/Shiva's hand. He had committed brahmanicide — the killing of a Brahmin, the gravest sin. Even though the act was justified, the sin adhered.
Shiva wandered for twelve years as a penitent, the skull of Brahma stuck to his hand, begging for alms with it as his bowl — the origin of the Kapalaika tradition.
The Liberation
He wandered until he reached Varanasi. The moment he stepped into Varanasi, the skull fell from his hand. The city freed him from the sin.
This is one of the reasons Varanasi is the most sacred city in the Shaiva tradition — the city where even the greatest sin of the greatest god can be dissolved.