All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger. We ask Allaah to exalt his mention as well as that of his family and all his companions.
Wearing such a hat is permissible as long as it does not look like the hat of non-Muslims because it is forbidden to imitate them. The Prophet said: "Whoever imitates a people he is one of them." [Ahmad and Abu Daawood] Therefore, if this hat is not a slogan of the non-Muslims or clothing that is peculiar to them, and the sentence mentioned: "La Ilaaha Illa Allaah Muhammadan Rasoolu Allaah" (None has the right to be worshipped but Allaah and Muhammad is His Messenger), then it is disliked to enter the toilet with it. This is the view of the majority of the scholars of the four schools and others, and there is no harm in wearing it without having ablution as it is not Qur'aan or a verse from the Qur'aan.
Allaah knows best.