In his ruling, Chief Justice Qazi Faez Isa said that life bans "abridge the fundamental right of citizens to contest elections."
Sharif cleared to run on February 8
Sharif, 74, was found guilty of dishonest practices in 2017 and disqualified from office under a subsequent ban the following year.
Last year, the courts overturned the two convictions, but he remained disqualified.
Sharif's party, Pakistan Muslim League-Nawaz (PML-N), is tipped as a front runner to win elections scheduled for February 8.
"Alhamdulillah (praise be to God), today the dark chapter of judicial injustice of lifelong disqualification to make Nawaz Sharif a target of political revenge has finally ended," Marriyum Aurangzeb, a PML-N leader, said on social media.
Sharif's main rival, former Prime Minister Imran Khan, is in jail amid an avalanche of legal cases. He has also been banned from politics for five years, and this was not impacted by Monday's judgement, which only applied to lifetime bans.
One of Khan's lawyers, Intazar Hussain Panjutha, described the scrapping of the lifetime ban on Monday as the "death of law and the constitution".