The answer to this question is a lot more interesting and complex than you might have expected given that it's about headwear. For centuries, clothing in the Ottoman Empire was used as a key means of showing your identity. Certain colors of headgear were assigned to certain groups, different ranks had different kinds of hat: The Sultan had his own, the Janissaries had their own varieties, depending on rank and roles, among different groups of commoners, and so on. The specific regulations encoded by Suleiman the Magnificent, who was also known as kanuni (lawgiver), stayed unchanged until the 1720s (that's about two centuries). Donald Quataert, whose paper I am citing expansively in this response, notes that this lack of change may have been a sign of "social rigidity", as changes in clothing laws tend to reflect social mobility. On top of that, clothing was also the most visible physical marker of identity, important in a "society organized along strictly religious lines." (Hanioğlu 2008, pgs. 28-29) This meant that you could go out onto the street and tell by what anyone was wearing what their religion was, what profession they may have held, and if they were government officials, what their rank and position was.
These sorts of clothing laws were also used to define social status, and were by no means limited to the Ottoman Empire. In medieval Burgundy, for example, there was a law that restricted the length of the points of shoes worn by commoners to six inches. Clothing was also used as a religious marker in medieval Europe, as Jews were required to wear distinctive markers to single them out as being Jewish. This could take the form of a particular form of hat, being restricted to only wearing certain colored garments, and/or yellow cloth badges. This last method would of course be brought back by the Nazis during the Holocaust.
Getting back to the Ottoman Empire, let's fast-forward to the reign of Selim III (1789-1807), a reformer who would wind up being deposed and murdered by the Janissaries. By this time, the Empire was in full-blown crisis: a revolt in Serbia (rooted in local backlash to the Janissaries) had started to spin out of control, while Egypt was decisively breaking away from Ottoman control under the rule of Muhammad Ali. No, not that Muhammad Ali, this Muhammad Ali.
Sultan Selim III (1789-1807) sought to use clothing laws in an attempt to win support for his rule from the artisans and the population at large. He contrasted himself with the high-ranking members of his government and extravegant aristocrats with his righteous support of local producers. Quataert quotes Selim:
I always wear Istanbul-made and Ankara-made cloth. But my statesmen wear Indian-made and Iranian-made cloth. If they would wear the cloths of our country, local goods would be in demand. (Quataert 1997, pg. 411)
This appeal was significant, since the artisan guilds had ties to the Janissaries, who Selim was trying to court with this policy. Ultimately, this didn't save him, but it marked a departure from prior clothing laws, which "primarily expressed a concern for morality, social discipline, and order, stressing extravagance and waste on the personal level." (Quataert 1997, pg. 412) While Selim did raise issues of corruption and bribery in devising these laws, his focus was also economic and political, trying to aid Ottoman artisans and so gain the support of the Janissaries. We will soon see this broader focus of clothing laws coming into play.
Selim III was succeeded by Mahmud II (1808-1839), another reformist, but during this time, things still went from bad to worse. Mahmud had to sign the Charter of Alliance with provincial notables, granting them greater autonomy in exchange for their needed support. Meanwhile, a revolt in Greece went totally off the rails, resulting in an independent Greece, while Muhammad Ali (who won control of Syria during this period) almost defeated the Ottoman Empire, and would only stopped from finishing the job by an intervention from the great powers. On top of that, the dismal financial situation went from bad to worse, with the currency becoming ever more inflated and devalued.
Drastic change was needed, and Mahmud II set out to do that. His overall goal was to legitimize and restore the power of central authority, and he served as a precursor to the effort to assert a common Ottoman identity (Ottomanism) that would emerge in the following decades. He finally crushed the Janissaries during the Auspicious Incident in 1826, eliminating what had become a festering ulcer and one of the biggest threats to reform. After this, he set out to organize a new army, adopting European-style uniforms coupled with the fez (with a cloth wrapped around it) for them. In 1829 he proclaimed an extremely detailed clothing law, but most significant change was that every single official (except for a few at the very top) would wear the fez. This was a massive departure from the past, essentially pressing a reset button when it came to differentiating different groups. It swept away the myriad markers of the old elite, be they holders of lifetime tax-farms, provincial notables, Janissaries (many of whom were now rotting corpses), and so on, while creating new markers for the new imperial bureaucracy that he was setting up. As the fez was worn by practically all members of the bureaucracy, this also signaled an abandonment of the old practice of differentiating among groups: before the sultan, all these officials would look equal, regardless of rank or creed. This reinforced the position of the Sultan as only one who could bestow ranks while removing visible markers of religious differentiation. "In using clothing laws to erode distinctions based upon religion and create a new base for this regime, Mahmud II offered non-Muslims and Muslims a common subjecthood/citizenry." (Quataert 1997, pg. 413) These sentiments were also expressed by the Sultan himself:
From now on I do not wish to recognize Muslims outside the mosque, Christians outside the church, or Jews outside the synagogue. (Hanioğlu 2008, pg. 74)
This uniformity was particularly significant at a time when the empire's hold over non-Muslims seemed to be slipping away, given the success of revolts in Serbia and Greece. This new Ottoman identity was visually stripped of its religious components, a change that would serve as prologue to the far-reaching Tanzimat reforms that would commence a decade later (1839-1876). The new headwear would be rapidly accepted by the bureaucracy, and by the upper and upper-middle classes, be they Muslims or non-Muslim.
However, it was resisted by Ottoman workers. Mahmud responded to this by having the army wear plain fezes (instead of fezes with turban wrappings) and allowing members of the artisan class to wear cloth wrappings around their fezes. Quataert cites one writer who attributes this resistance to the ultra-conservatism, fanaticism, and pro-Janissary leanings of the artisan class, which he partially accepts. He adds, however, that he believes that the artisans were insisting on a differentiation between themselves and the "offical class for religious reasons, because the official class now could and did include non-Muslims, who wore fezes that disguised their religious affiliation." (Quataert 1997, pg. 414) Alternatively, he also puts forth the argument that the rejection of the plain fez was "an expression of a distinctive workers' culture among both Muslims and non-Muslims," which tracks with interactions between workers and the state during this period. Essentially, this would mean that the rejection of the fez was meant to show their rejection of Mahmud II's economic policies, which involved a laissez-faire approach and the dismantling of the guilds, now that they no longer enjoyed the protection of their Janissary allies. That would mean that wearing the plain fez signaled support for the Sultan's policies, as demonstrated by the bureaucrats and the non-muslim merchants who rapidly embraced the new headwear. The workers, on the other hand, rejected these policies, the fez, and the sultan's policies in general.
Months after passage of the 1829 clothing law, workers of Istanbul who had been dragooned into the Ottoman army defending Edirne threw off "the obnoxious fez." One soldier asked "How can you expect them to fight... with this thing on their heads." (Quataert 1997, pg. 416)
This rejection of the plain fez by members of the artisan class continued throughout the rest of the 19th century, be they muslim or non-muslim. Mahmud II had originally intended to make the plain fez universal throughout Ottoman society, but he was forced to back down in the face of this successful resistance to imposition of the fez. He had other, far more pressing problems on his plate. In spite of this, Mahmud's clothing reform was one of the most visible steps towards reform in the first third of the 19th century.
Sources:
Quataert, Donald. "Clothing Laws, State, and Society in the Ottoman Empire, 1720-1829." International Journal of Middle East Studies 29, no. 3 (1997): 403-25. http://www.jstor.org/stable/164587.
Hanioğlu, M. Şükrü. 2008. A Brief History of the Late Ottoman Empire. Princeton, New Jersey: Princeton University Press. ISBN 978-0-691-14617-1