Devin Kelley, who police say murdered 26 people at a rural Texas church yesterday, seems to have been legally disqualified from owning a gun. It's not clear why he repeatedly passed federal background checks while purchasing firearms, including the Ruger AR-556 rifle he used in the attack, which he bought last year from an Academy Sports & Outdoors store in San Antonio.

The Air Force says Kelley, an airman who served in logistics readiness at Holloman Air Force Base in New Mexico, was convicted by a court martial in 2012 of two counts under Article 128 of the Uniform Code of Military Justice, which applies to assault. The victims were his wife, from whom he was subsequently divorced, and their child. Kelley's punishment was 12 months of confinement, a reduction in rank, and a bad-conduct discharge.

As Christian Britschgi noted this morning, the discharge itself would not have prevented Kelley from legally buying a gun, since it fell short of the "dishonorable conditions" specified by federal law. But the same law prohibits the purchase or possession of a gun by anyone who "has been convicted in any court of a misdemeanor crime of domestic violence." Kelley's crimes seem to fit the definition of that phrase, which includes "the use or attempted use of physical force" by a spouse or parent of the victim.

The form that Kelley would have filled out while buying guns from Academy or any other federally licensed dealer asks, "Have you ever been convicted of a misdemeanor crime of domestic violence?" Kelley presumably checked "no," but the FBI's National Instant Criminal Background Check System (NICS), which includes the National Criminal Information Check (NCIC) database, should have flagged the court martial convictions.

According to a 2001 article in The Military Lawyer, "A court-martialed soldier convicted of a reportable offense entered into the NCIC/NICS will be denied the sale of a firearm." A footnote says reportable offenses include cases involving "a dismissal or punitive discharge" or "conviction of an offense that carries a possible sentence of confinement of one year or more."

In a CNN interview, Texas Gov. Greg Abbott said Kelley had applied for a concealed carry permit but was rejected by the state's Department of Public Safety. "So how was it that he was able to get a gun?" Abbott asked. "By all the facts that we seem to know, he was not supposed to have access to a gun. So how did this happen?"

The criteria for a Texas carry permit are stricter than the federal criteria for gun ownership. People who have been convicted of a Class A or B misdemeanor in the previous five years, for instance, are ineligible for a carry permit. But if the state's background check flagged Kelley's military convictions, why didn't the FBI's?

Although mass shooters typically do not have disqualifying criminal or psychiatric records, it looks like Kelley did. But as with Dylann Roof, the perpetrator of another horrifying assault on a church, the system that is supposed to catch people who are not legally allowed to buy guns failed to do so.

President Obama cited Roof's attack in making the case for "universal background checks," meaning a legal requirement that all gun transfers, not just those involving federally licensed dealers, receive the FBI's approval. Since Roof passed a background check, that argument did not make much sense. The problem was not the absence of a background check but the inadequacy of the background check that was performed. The same thing seems to be true in this case.

Update: USA Today reports that Kelley was tried by a general court martial (as opposed to a special court martial, which is for less serious offenses and can impose terms of confinement no longer than 12 months). If so, Kelley would have been doubly disqualified from buying a gun: because conviction by a general court martial is treated as equivalent to a felony conviction in a civilian court and because separation from the armed forces ordered by a general court martial is treated as equivalent to a dishonorable discharge.

Update II: Citing an unnamed "defense official," USA Today reports that "the Air Force failed to enter Kelley's conviction in the National Crime Information Center database." The paper adds that "the Air Force was required to provide the information to the database because Kelley was convicted of a domestic assault and would not have been able to purchase a gun legally."