Umaru Abdullahi, the presiding judge, said the government's December decision was "unconstitutional, illegal, null and void and of no effect whatsoever".
Adebayo Adenipekun, a lawyer for the government, said it planned to lodge an immediate appeal with the supreme court.
"We believe the supreme court will reach a different decision," he said.
Brutal military rule
Obasanjo and Abubakar were elected together in 1999 after a period of brutal military rule.
The pair fell out publicly last year after Obasanjo's supporters tried to amend the civilian constitution's term limits and allow Obasanjo to run again this year.
Abubakar, who long held presidential ambitions, refused to support the amendment, and the two leaders traded accusations of corruption before Abubakar bolted from the party.
The country's anti-corruption watchdog has announced that it is investigating Abubakar for corruption, but he is immune from prosecution while in office.
Any candidate convicted in a court of law on corruption charges would be prohibited from running.
Nigeria has a turbulent history of coups and military dictators, and April's polls should mark the first time one elected government hands power to another since the country first became independent from Britain in 1960.