His relatives and supporters condemned the decision, saying they wanted proof that it was his body.
The High Court said it lacked jurisdiction over the case.
Seen by many as Africa's Che Guevara, Mr Sankara was hastily buried after being killed during a 1987 coup led by incumbent President Blaise Compaore.
The anti-imperialist revolutionary became president in 1983 after an internal power struggle and led his country for four years.
The court's ruling was greeted with outrage and contempt by Mr Sankara's relatives and supporters, reports journalist Chris Simpson from the capital, Ouagadougou.
Campaigners say the family never had the chance to identify his body before he was buried in the capital's Dagnoen cemetery.
About 100 people protested outside court, chanting "down with the Burkinabe judiciary" and "when will the Burkinabe people know the truth?", AFP news agency reports.
Mr Sankara was killed by a group of soldiers at the age of 37.
Public interest in Mr Sankara remains high in Burkina Faso, with opposition group demanding answers about his death, correspondents say.
Family lawyer Benewende Sankara said he would appeal against the decision.
"We are not happy," AFP quoted him as saying.
President Compaore has so far refused to agree to Mr Sankara's exhumation, and has always denied being involved in the ex-leader's killing, Chris Simpson reports.
Mr Compaore insists the "facts are known" and he has "nothing to hide", he adds.
When Thomas Sankara took power in 1983 he changed the West African state's colonial name of Upper Volta to Burkina Faso, which means "the land of upright men".
His supporters say he was incorruptible, unlike many other African leaders.
Mr Sankara was seen as charismatic and wore a beret, leading to comparisons with the Latin American revolutionary Che Guevara.
Many taxis across West Africa still have a round sticker of him on their windscreens.
A court in Burkina Faso has refused to rule on a request by the family of ex-President Thomas Sankara for his body to be exhumed for DNA tests.