A judge in Lagos on Friday upheld a ban on the Muslim headscarf in state-run schools, ruling that the restriction did not breach students' civil rights.
The Muslim Students Society of Nigeria brought the case challenging the ban on wearing the hijab in public primary and secondary schools, which was introduced in Lagos State last year.
Judge Modpue Onyeabo, sitting at the High Court in Lagos, said in her ruling: "The application fails in its entirety.
"The ban on the use of hijab in public schools in Lagos is not a breach of the applicants' fundamental rights to religion because Nigeria as a secular state does not adopt any religion as a state religion.
"Removing the ban on the hijab will be tantamount to promoting a particular religion against the others and this may lead to social tensions."
The Lagos State government introduced the ban in May 2013, three months after Muslim groups reacted in outrage at a school principal who flogged a female student for wearing the hijab at a secondary school.
Constitutionally secular Nigeria is almost evenly split between a Muslim-majority north and predominantly Christian south.
Religion, however, is never far from the surface in public discourse, with politicians regularly referring to their faith, while tensions frequently boil over into communal violence.
In the country's northeast, Boko Haram militants are fighting to create a hardline Islamic state, while sharia -- Islamic law -- is run as a parallel justice system in many northern states.
The applicants' lawyer, Shakirullahi Obale, said the Muslim Students Society of Nigeria was not satisfied with the ruling and said they would appeal to a higher court.
Religious education is taught in state schools and there is no apparent ban on religious symbols such as crucifixes.
In her judgment, judge Onyeabo added: "The state policy on dressing code is to promote public order and peace.
"The use of common uniform is for identification and to foster a sense of unity in public schools in the state. All applicants into a public school must obey the school's rules and regulations, including the dress code."
More than 200 campaigners, most of them young girls in the hijab, which covers the hair and upper body, were both inside and outside the court to support the challenge.