The attacker from the Tehreek-e-Taliban's Jamaat-ur-Ahrar faction apparently wanted to hit lawyers at the bar room, police said.
When a policeman stopped him at the gate, the bomber threw a grenade at him and detonated his explosives laden vest among the morning crowds at the main gate of the courts.
"First there was a small blast followed by a big blast," chief rescue officer in Mardan Haris Habib said.
"So far we have recovered 12 bodies of lawyers, police personnel and civilians. Besides this, we rescued 52 injured, including lawyers, police personnel and civilians from the spot," Habib was quoted as saying by the Express Tribune.
More From This Section
The injured have been shifted to a nearby hospital. A state of emergency has been declared at local hospitals and security has been tightened in all adjoining areas.
Police officials said that the suicide bomber had between seven and eight kilogrammes of explosives on his body.
Army chief Gen Raheel Sharif visited the Mardan Medical Complex and inquired after the injured victims of the blast.
The Quetta attack was also claimed by Jamaat-ur Ahrar.
Today's assault on court occurred hours after four heavily-armed suicide attackers from the same faction tried to storm a Christian colony in Peshawar, some 40 kilometers from Mardan, but were gunned down by security forces.
In the predawn attack, the terrorists struck the colony near Warsak Dam, just north of Peshawar, and killed one Christian security guard.