A federal judge has ruled that a Mexican national who was taken into custody for deportation and kept in a cell for nearly two years is entitled to a bond hearing.

Juan Vega was arrested and served time for drug trafficking and served a yearlong prison sentence. In November 2016, he was taken into custody by U.S. Immigration and Customs Enforcement and put in a York County prison where he stayed for 21 months awaiting removal proceedings.

Vega in court filings claimed that he was subjected to an unconstitutionally long stay in prison and had been denied due process rights by having the bond hearing put off for so long.

U.S. District Judge Malachy Mannion of the Middle District of Pennsylvania, adopting the findings of his colleague U.S. Magistrate Judge Karoline Mehalchick, ruled in favor of Vega. An important issue in the case was also whether the amount of marijuana Vega sold—50 pounds—was enough to be considered an aggravated felony, which would weigh in favor of hastened deportation.

While the warden of the prison argued that Vega was trying to delay the inevitable, Mannion said, “petitioner Vega did not request multiple continuances during his removal proceedings. Nor does the court find that any delay in petitioner Vega’s removal proceedings are attributable to him. In fact, it does not appear that either party has caused any delays in the removal proceedings.

“Rather, the delay in the petitioner’s removal proceedings appears to be resolving the difficult question of whether the petitioner’s conviction … constitutes an aggravated felony making him ineligible for cancellation of removal,” Mannion continued. “The court does not find that the petitioner is filing frivolous appeals. All of the briefs in the petitioner’s current appeal with the Third Circuit have not yet been filed and, there is no way to know how long his appeal will be pending. As stated, the Third Circuit granted the petitioner a temporary stay of removal.”

Mannion added, “Thus, the facts that the petitioner’s removal is not imminent and he has asserted a valid defense to his removal coupled with the fact of the length of his detention weigh in favor of the court’s finding that his continued detention is unreasonable, and unconstitutional, as applied to him, entitling him to a bond hearing. Indeed, it is relevant that petitioner Vega’s detention for almost two years in [York County Prison] is comparable to a considerable prison sentence even though he was not convicted of any new crimes”

John J. Buckley III of Norris McLaughlin & Marcus in Allentown represents Vega and did not return a call seeking comment.