Two policemen, a policewoman and a child were among those killed in the blast on Monday in the town of Shabqadar in Charsadda district, said police official Ali Jan Khan.
He said that the death toll rose after six of the more than 20 people wounded died in hospitals overnight.
A group affiliated with the Pakistani Taliban and calling itself Jamat-ul-Ahrar claimed responsibility, describing it as an attack on the judiciary which "gives verdicts against God's divine laws."
Ahrar's spokesman Ahsanullah Ahsan said that the court bombing was in revenge for the hanging of Mumtaz Qadri, who was executed last week for the 2011 killing of a provincial governor.
The local Taliban branch and its allied militant groups have been waging a war against the state for over a decade, killing tens of thousands of people.
Charsadda district, where four suicide bombers from a Pakistani Taliban-linked group killed 21 students and teachers on Jan 20, is located at the edge of Pakistan's tribal region, near the Afghan border.
Pakistan's military says it has entered the final phase of an offensive against the militants in the tribal region.
Overnight airstrikes targeted several hideouts in the town of Shawal, killing 21 militants, according to a statement by the Pakistani army.
Death toll from Sri Lanka bombing attacks rises to 359: police