Justices of the US Supreme Court on Tuesday contemplated, for a brief moment, whether it might be possible to hide a revolver in a prison inmate’s beard.

That remote possibility arose near the conclusion of oral argument in a case testing whether an Arkansas inmate is entitled to a religious accommodation from state prison officials to allow him to grow a beard in accord with his Muslim beliefs.

Arkansas officials refused, insisting that their policy requiring inmates be clean shaven was necessary to maintain the security of their prison system. They say their decision on how best to maintain the security of Arkansas’ prisons deserves deference from the courts.

But a lawyer for the Muslim inmate countered that more than 40 other state prison systems and the federal Bureau of Prisons allow inmates to grow facial hair. The lawyer, Douglas Laycock, said there were no examples of a prisoner attempting to use a beard to conceal a weapon or contraband.

The justices appeared skeptical of Arkansas’ position that it could not offer an accommodation without undercutting security.

At one point, Justice Samuel Alito asked Arkansas Deputy Attorney General David Curran how hard could it be to ask a bearded inmate to run a comb through his facial hair.

“If there’s a revolver in there it will fall out,” he said, drawing laughter in the courtroom.

Mr. Curran responded that there is no perfect way to search inmates.

Justice Alito insisted that such a search would not be too difficult for prison officials.

Curran conceded that it sounded like something that could be done.

Earlier, he said that, despite what other states might do, Arkansas’ prisons are run differently and require tighter security measures.

Inmates in Arkansas are assembled into work details and make daily trips outside the prison to work in fields or on other projects, he said. Other states keep their inmates locked securely inside prison walls throughout their sentences.

Curran added that officials were also concerned that an escaped prisoner might significantly alter his appearance by quickly shaving his beard. But the justices pushed back with suggestions that such an effort could be defeated by keeping photos of inmates both clean shaven and bearded.

Although the case touches on security measures, it is ultimately about religious liberty and a federal statute designed to protect it.

At the heart of the dispute is a request from inmate Gregory Holt, also known as Abdul Maalik Muhammad, that he be allowed to grow a beard.

He explained to prison officials that he wished to follow the teachings of the Prophet Mohammed, including an instruction that Muslim men allow their beards to grow.

Although the Prophet’s directive is that Muslim men allow their beards to grow without cutting them, Mr. Holt offered a concession. He said it would be acceptable to him if he were allowed to grow a ½-inch beard, which at one time was the standard allowable for inmates in California.

Prison officials refused.

Arkansas does have an exception: Inmates with a skin condition are allowed to grow a ¼-inch beard, but only if ordered by a physician. Prison officials declined to offer a similar accommodation for Muslim beards.

Holt sued. He argued that, under the Religious Land Use and Institutionalized Persons Act, state and federal governments are required to offer an accommodation when public policies clash with religious beliefs.

Under the law, the government only can avoid providing an accommodation if it demonstrates that the targeted policy advances a compelling interest and that it does so through the least restrictive means.

The justices decided last year’s Hobby Lobby case based on a similar law, the Religious Freedom Restoration Act.

In Holt’s case, a federal magistrate judge, a district judge, and a federal appeals court panel all concluded that Arkansas was justified in denying Holt’s request.

Almost out of options, the inmate sent a handwritten petition to the Supreme Court, asking for justices to order the lower courts to offer a religious accommodation. The court issued an injunction to allow Holt to grow his beard. The justices then also agreed to hear his case.

Mr. Laycock, a law professor at the University of Virginia and a nationally recognized religious liberty scholar, told the justices that Arkansas had failed to justify its policy and failed to justify its refusal to provide an accommodation.

Speculation and exaggerated fears are not enough, he said.

“The question is how much deference is due to prison officials,” Laycock said. He added that degree of deference must be tied to the quality of their offered justification and the nature of the requested accommodation.

The case is Holt v. Hobbs (13-6827). A decision is expected by June.