The state administrative court in the southwestern city of Stuttgart ruled that teachers may be kept from covering their heads in the classroom if they do so for religious reasons.
The decision overturned a ruling by a lower court in July 2006, saying that the teacher had a right to wear the headscarf because Roman Catholic nuns elsewhere in the state wore habits when they taught at a public school.
"The directive issued by the school administration for those working at the school not to wear such a head covering is lawful," the court said in a statement, summarizing the ruling made on Friday.
"This also applies when the teacher in question is an employee with tenure who has worked at a school for several years with such a head covering without complaints from pupils or students."
The plaintiff, who has taught at a joint elementary and secondary school for more than three decades, converted to Islam in 1984. She had worn a traditional Muslim headscarf in the classroom since 1995 during which time no objections were raised.
But in December 2004, the school board in the state capital Stuttgart ordered her to stop covering her head in the classroom on the grounds that it could influence impressionable children, prompting her to go to court.
The Mannheim court ruled that with the headscarf, the teacher was violating her obligation to keep religious expression out of the classroom and that the ban fully complied with the country's Basic Law.
Baden-Württemberg was the first of Germany's 16 states to ban the headscarf in schools after it was outlawed in France in 2004.
The French ban sparked a heated debate in Germany and the Constitutional Court, the country's top court, finally ruled that each state had the right to make its law in this regard. So far eight out of Germany's 16 states have ordered teachers not to wear the headscarf at schools, though Muslim pupils are generally allowed to do so.
Germany is home to three million Muslims and the biggest Turkish community outside Turkey.