WASHINGTON, April 20 — Under federal law, the Virginia Tech gunman Seung-Hui Cho should have been prohibited from buying a gun after a Virginia court declared him to be a danger to himself in late 2005 and sent him for psychiatric treatment, a state official and several legal experts said Friday.

Federal law prohibits anyone who has been “adjudicated as a mental defective,” as well as those who have been involuntarily committed to a mental health facility, from buying a gun.

The special justice’s order in late 2005 that directed Mr. Cho to seek outpatient treatment and declared him to be mentally ill and an imminent danger to himself fits the federal criteria and should have immediately disqualified him, said Richard J. Bonnie, chairman of the Supreme Court of Virginia’s Commission on Mental Health Law Reform.

A spokesman for the federal Bureau of Alcohol, Tobacco, Firearms and Explosives also said that if Mr. Cho had been found mentally defective by a court, he should have been denied the right to purchase a gun.