The alleged shooter tried to escape in a vehicle after the attack in the city of Beaumont, about 80 miles east of Houston.
One victim was hit by the suspect's lorry as he tried to get away.
The suspect had come to court with family members, but police did not say why he was there.
In a news conference, deputy police chief Zena Stephens confirmed the suspect was injured by police returning fire outside the courthouse. One person ran into the courthouse for safety after being shot, she said. After abandoning the lorry in a nearby street, the suspect ran into a nearby building and took hostages.
Local and county police surrounded the building and contacted the suspect by telephone. He then handed the gun to people inside and gave himself up to police. The alleged shooter was then brought to a nearby hospital.
Police say they will not release the identity of the person shot dead until the family is notified.