Four people were killed and 47 wounded in the attack, said Habib Arif, a senior government official in Peshawar. Twenty of the wounded were discharged from the hospital after receiving first aid, while 27 remained under treatment, said Arif.
The judge presiding over the session inside the courtroom was among the wounded, said police officer, Mohammad Arshad Khan.
Naeem Ullah was standing outside the courtroom when the bomber blew himself up.
The blast "caused all of the glass in the windows to break, and I was wounded in my leg and back," said Ullah. He spoke while receiving treatment at a local hospital.
Ahsan, the Pakistani Taliban spokesman, claimed responsibility for the attack without providing details.
The motive for the attack was not immediately clear.
The attackers may have been trying to free militant colleagues jailed on the premises of the compound, said Mian Iftikhar Hussain, the information minister for Khyber Pakhtunkhwa province, where Peshawar is the provincial capital.
Local TV footage showed people running for safety, including wounded people being assisted by others. Police commandos and army soldiers rushed toward the complex, as the wounded were shifted to stretchers and taken to the hospital.
Peshawar is located on the border of Pakistan's semiautonomous tribal region, the main sanctuary for the Pakistani Taliban, who have carried out scores of bombings in the city.
In the southern port city of Karachi, paramilitary forces arrested a militant leader involved in the kidnapping and murder of Wall Street Journal reporter Daniel Pearl in 2002, said two paramilitary officials, speaking on condition of anonymity because they were not authorized to talk to reporters.
Qari Abdul Hayee, a former leader of the Lashkar-e-Jhangvi militant group in southern Sindh province, was arrested on Sunday in Karachi, said the paramilitary officials. He also went by the name Asadullah and was involved in other attacks in Karachi as well, they said.
Lashkar-e-Jhangvi is a radical Sunni Muslim militant group that has carried out many attacks in Pakistan, especially against minority Shiite Muslims.
Also in Karachi, gunmen riding on a motorcycle shot to death a Shiite professor, Sibt-e-Jafar, on Monday, said police officer Amir Farooqi.
No group claimed responsibility for the latest attack in Karachi.
Associated Press writers Zarar Khan and Asif Shahzad in Islamabad and Adil Jawad in Karachi, Pakistan, contributed.