aww,
The hat is sunnah. There are many hadiths which show that the prophet (Saw) wore a hat in prayer.
Wail ibn Hajr mentions how he looked at the congregation and they were wearing hats (http://sunnah.com/abudawud/2/338).
In another hadith, the Prophet (Saw) says that "The difference between us and the polytheists is that we wear turbans over CAPS" - the polytheists wore turbans without caps, while the Muslims wore caps first, and turbans on top. Thus, the wearing of caps is sunnah (http://sunnah.com/tirmidhi/24/73 - note that Albani calls this narration weak, but his gradings are contested).
Also, in Hajj, the Prophet (saw) instructed everyone not to wear hats, which shows that it was normal for them to wear hats. This is further proof that hats were worn.
Furthermore, there is a hadith in which Umar (ra) or the Prophet (Saw)'s hat falls off, which again indicates that hats were worn.
The large body of hadiths on the wearing of caps indicate that it is sunnah to wear them.
Some people say that hats were worn outside prayer but not in prayer. This is unlikely. If it were true, there would be lots of hadiths describing how the Prophet (Saw) and sahaba took off their hats before praying. Such hadiths don't exist, which means this didnt happen.
some more hadiths on hats are here: http://sunnah.com/search/?q=%D9%82%D9%84%D9%86%D8%B3%D9%88%D8%A9
wwb