The ruling, announced on Thursday, stipulates that convicted criminals should go to prison only after they have exhausted their appeal options.
The change could lead to the release of thousands of prisoners, including Lula. The left-winger led Brazil between 2003 and 2010, but was jailed last year.
He was favourite to win last year's presidential election but was imprisoned after being implicated in a major corruption investigation.
Lula has consistently denied all the accusations against him and claims they are politically motivated.
After he was barred from running, right-wing candidate Jair Bolsonaro went on to win the race. Lula's lawyers say they will seek the former president's "immediate release" after speaking to him on Friday.
What was the ruling?
Justices voted to reinterpret the country's penal code in a six-five vote issued on Thursday.
It overturns a three-year-old rule which mandated immediate prison time for convicted criminals after they lost their first appeal.
Brazil's corruption scandal, known as Operation Car Wash, initially centred on the state-run oil company Petrobras, but subsequently, billions of dollars of bribes were uncovered - and dozens of high-profile business leaders and politicians were jailed.
The mandatory imprisonment rule was seen as helping prosecutors secure convictions and unravel the major corruption scandal by encouraging suspects to negotiate plea deals.
But critics claimed it violates Brazil's constitution - which states that no one can be deprived of their liberty without due process of law.
The country's Car Wash task force described Thursday's overturning as being "inconsistent" with efforts to fight corruption.
The proposed change was also opposed by Sergio Moro, the judge who sentenced Lula, who is now serving as Mr Bolsonaro's justice minister.
Chief Justice Jose Antonio Dias Toffoli, who cast the deciding vote, said releases would be made on a case-by-case basis.
The change could affect almost 5,000 prisoners, according to National Council of Justice estimates.
What was Lula accused of?
Lula was jailed in 2018 after being sentenced to more than 12 years in prison, later reduced to eight years and 10 months, for receiving a beachside apartment from an engineering company implicated in the Car Wash investigation.
Earlier this year, he was sentenced to another 12 years after being found guilty of accepting bribes in the form of renovation work at a country house from construction companies.
Lula, 74, argues all the charges made against him are politically motivated. He is former trade union activist and remains an iconic and popular figure for the left.
Gleisi Hoffman, the leader of Lula's Worker's Party, called Thursday's development "a very important step to strengthen democracy and the constitution at a time when they are under threat from an extreme-right government."
More about: Brazil