Sheikh Ahmad al-Khalîl, professor at al-Imâm University, Qasîm Branch
It is known that the Prophet (peace be upon him) wore a turban. `Amr b. Hurayth said: “I saw the Prophet (peace be upon him) on the pulpit and he was wearing a black turban with its ends resting on his shoulders.” [Sunan Abî Dâwûd].
In another narration in Sahîh Muslim it reads: “It is as if I see the Prophet (peace be upon him) wearing a black turban having each end laying on each side.”
Also, al-Tirmidhî narrated that the Prophet (peace be upon him) wore a black turban, laying each end between his shoulders.
This was also a mode of dress employed by the Companions. Nâfi` relates that Ibn `Umar used to wear a turban. `Ubayd Allah relates that he saw al-Qâsim and Sulaym wearing it.
As for the ruling on wearing a turban in Islamic Law, this is a matter of disagreement among scholars. Some say it is Sunnah to wear a turban, because the Prophet (peace be upon him) wore it, while others say that this is something that depends purely on custom. They argue that the Sunnah is to dress according to what is deemed correct and proper within the context of customs and tradition. Customs and traditions vary from time to time and from place to place.
This argument is even more applicable to a mere hat.
And Allah knows best.
Source: Islam Today