A federal appeals court ruled Tuesday that a visiting judge who ordered the District to stop enforcing its strict laws for carrying concealed firearms had no authority to hear the case.

In a unanimous decision, a three-judge panel of the U.S. Court of Appeals for the D.C. Circuit said the judge from upstate New York was erroneously assigned to the case after hearing an earlier, related challenge to the city’s gun-control laws.

“We realize that we are undoing the work of litigation to date, but we have no choice,” wrote Judge David B. Sentelle, who was joined by Judges Cornelia T.L. Pillard and Laurence H. Silberman.

The court’s decision means that the case will almost certainly be assigned to a D.C.-based federal judge to hear the ongoing challenge to a provision of the law that requires a person to state a “good reason” to carry a firearm on the streets of the nation’s capital.

D.C. Attorney General Karl A. Racine called the ruling “good news for public safety” and said the case probably will be heard “before a judge from our community — something that we have argued is crucial to understanding the public-safety issues at stake.”

The case began in the spring when U.S. District Judge Frederick J. Scullin Jr., ruled that the city’s concealed-carry law “impinges” on the Second Amendment right to bear arms. The appellate court in June overturned Scullin’s preliminary injunction and allowed the city to continue to enforce its rules until a final decision could be reached about whether the law is constitutional.

Scullin, a senior judge, was initially appointed in 2011 by the chief justice to help with a backlog at the District Court, including an earlier challenge to the city’s previous outright ban on carrying firearms in public. D.C. government lawyers appealed Scullin’s injunction and said he was not properly assigned to preside over the subsequent case.

Alan Gura, an attorney representing members of the nonprofit Second Amendment Foundation in both cases, said Scullin’s authority was not “time-limited.” He noted that lawyers from the D.C. Attorney General’s Office had not raised concerns about the judge’s authority until after the appellate court highlighted the issue.

On Tuesday, the appeals court sided with the city, saying that Scullin’s authority was limited to the initial case and that his original designation “did not extend beyond the specifications of that designation.”

“While the earlier case was within the Chief Justice’s designation, the present one is not.”

The court’s ruling did not touch on the substance of the District’s public-carry law that is similar to those in Maryland, New York and New Jersey. The city’s law leaves it up to the police to license only individuals who have shown “good reason to fear injury” that is supported by “evidence of specific threats or previous attacks.”

Gura said Tuesday that he would not ask for a rehearing by a full panel of the appellate court.