(CNN) The Supreme Court held on Tuesday that the government can detain -- without a bond hearing -- immigrants with past criminal records, even if years have passed since they were released from criminal custody.

The case centered on whether detention without a bond hearing must occur promptly upon an immigrant's release from criminal custody or whether it can happen months or even years later when the individual has resettled into society. The statute says simply that the detention can occur "when the alien is released" from custody.

The court voted 5-4 in favor of the government.

The challenge was brought by lawful permanent residents who committed a crime that could lead to their removal.

In his opinion for the court, Justice Samuel Alito said that the immigrants in the case had argued they were "owed bond hearings" in order to argue for their release. Alito said that the law did not support their argument.

Read More