A high court in Karnataka has ruled that the hijab is not "essential" to Islam in a landmark case that could have implications across the country.
The court also upheld a state government order that had banned headscarves in classrooms.
The verdict follows a months-long, divisive row over the hijab.
A Karnataka college's decision in January to bar entry to Muslim girls wearing the hijab had sparked protests.
The issue soon snowballed, forcing the state to shut schools and colleges for several days.
The matter reached the high court after some Muslim women protesters filed petitions arguing that India's constitution guaranteed them the right to wear headscarves.
The three-judge bench held that allowing Muslim women to wear the hijab in classrooms would hinder their emancipation and go against the constitutional spirit of "positive secularism".
The 129-page order quotes passages from the Quran and books on Islam to argue that the hijab is not an obligatory religious practice.
The order says, "There is sufficient intrinsic material within the scripture itself to support the view that wearing hijab has been only recommendatory, if at all it is. What is not religiously made obligatory therefore cannot be made a quintessential aspect of the religion through public agitations or by the passionate arguments in court.''
The petitioners had argued that a February order by the government prescribing uniforms in educational institutions violated their constitutional rights.
The court, however, said the order was valid, holding that the government had the right to prescribe uniforms for students.
"This is a pre-eminently fit case to go before the Supreme Court," - Prof Ravi Varma Kumar, a senior advocate who appeared for one of the petitioners.
"We had so much hope in our judicial system and our constitutional values. We feel we have been betrayed by our own country," Aliya Assadi (petitioner).
"I am not going to go to college without my hijab. And I will fight for it because the hijab is an essential part of my religion," Almas AH (petitioner).
While hearing the case, the bench had passed a contentious interim order that said students couldn't wear religious clothing - including the hijab - until it pronounced a verdict.
This led several Muslim women to skip classes and even their exams while the case was being heard.
The row started in in Karnataka's Udupi district after a government college barred six teenage students from wearing the hijab in class.
The college said it allowed students to wear the hijab on campus and only required them to remove it inside the classroom. But the girls, who all wore the mandatory college uniform, started a strike outside the college, arguing that they should be allowed to cover their hair in the classroom.
The protests soon spread to other colleges in the state, which is also governed by the BJP. Some Hindu students began going to classes wearing saffron shawls - the colour is seen as a Hindu symbol - which forced officials to insist that both could not be allowed on campus.
The issue attracted international attention after some demonstrations spiralled into violence - Nobel Prize-winner Malala Yousafzai tweeted about the issue, asking India's leaders to do something to "stop the marginalisation of Muslim women".