LOS ANGELES -- An Egyptian flight student who was arrested after he wrote on his Facebook page that he would be willing to serve a life sentence for killing Donald Trump agreed Friday to leave the United States by July.

Immigration authorities will allow Emadeldin Elsayed, 23, to return home voluntarily instead of deporting him, as long as he departs by July 5. Elsayed has not been charged with a crime but had his visa revoked by the State Department and is being held at a Southern California jail.

His lawyer, Hani Bushra, told Immigration Judge Kevin Riley in Los Angeles that he may seek another bond hearing for the aspiring pilot from Cairo because he believes Elsayed's detention is illegal.

Bushra said after the hearing that he understands why the Feb. 3 Facebook post led to his client being investigated. But in the absence of criminal charges, Elsayed should be freed, the attorney said.

"He's being detained, I think, primarily because he's a Muslim and he's a Middle Easterner," Bushra said, adding that social media sites are teeming with similar comments. "This kid is going to become a poster boy for hating America."

Immigration and Customs Enforcement arrested Elsayed at his Los Angeles-area flight school on Feb. 12, eight days after the Secret Service interviewed him about his post on the Republican presidential front-runner.

Get Breaking News Delivered to Your Inbox

U.S. officials often use immigration laws to quickly remove people from the country who are suspected of crimes rather than drag out a lengthy prosecution, said Claude Arnold, a recently retired special agent in charge of ICE's homeland security investigations in Los Angeles.

"It accomplishes the same goal: You neutralize the potential threat," Arnold said, adding that the goal is to protect Trump and public safety.

Threatening a presidential candidate is a crime, regardless of a person's immigration status, Arnold said.

"If you are a guest, you are more vulnerable if you do something stupid like that," he said.

Elsayed said in a phone interview earlier this week that Trump's comments about Muslims angered him, but he never intended to hurt anyone.

Trump has used especially tough talk on immigration during his campaign. He has vowed to build a wall along the entire Mexican border and called for a temporary ban on Muslims entering the U.S.

Elsayed said the agent who interviewed him mentioned last year's shooting rampage by a Muslim couple in San Bernardino and the Sept. 11, 2001, terror attacks, which were carried out by Muslims who had sought flight training in the United States.

Elsayed said he would seek a refund of some of the $65,000 he spent to pursue his pilot's license and try to get it elsewhere.

Immigration authorities said the flight school tipped off investigators to Elsayed's Facebook post, Bushra said.

Alex Khatib, owner of Universal Air Academy, said he was not aware of the case until federal agents showed up to interview and later detain Elsayed.