MONTGOMERY, Ala. — An Alabama man is mentally incompetent to stand trial on charges of threatening President Barack Obama’s life, and prison officials should determine whether he was also incapacitated at the time of the alleged offense, a federal judge ruled.

U.S. District Judge Myron Thompson issued an order Monday saying Deryke Matthew Pfeifer of Ozark, Ala., cannot be put on trial on a felony charge of threatening the president.

But, Thompson said, federal authorities can hold Pfeifer for as long as four months to determine whether he can regain his sanity, and the Bureau of Prisons should also evaluate the man to determine his mental status before his arrest earlier this year.

The decision followed a hearing last month in which a mental health expert testified that Pfeifer is delusional. Evidence showed Pfeifer told a psychologist that God is upset with Obama, particularly over his condoning same-sex relationships.

Pfeifer was arrested in July on charges of threatening Obama in phone calls to the Federal Protective Service and in online videos. In one video, he held a handgun.

© 2014, Associated Press, All Rights Reserved.

This material may not be published, broadcast, rewritten, or redistributed.