Wearing a hat has become so widespread in the orthodox community but what is it’s origin? Is it based off of anything from the Torah or Chazal? How old is the custom to wear a hat? And when did it become so widespread?
This is actually a very complicated question. I will begin by discussing any religious or Torah requirements regarding a head covering, then talk about hats and their relationship to Jews.
There is no religious origin to wear a "hat." By all accounts wearing a hat is a non Jewish custom. The closest thing to an official Torah based Jewish head covering is a Sudra, which is some sort of turban like head covering. The Talmud says If one wants to cover his head one should wear a head covering that wraps around the head such as a turban and say the blessing "Blessed are you Lord our God who crowns Israel with splendor."
כי פריס סודרא על רישיה לימא ברוך עוטר ישראל בתפארה
When he spreads a sudra over his head he should say: ‘Blessed is He who crowns Israel with glory’
Brachot 60b, Talmud Standard Vilna edition
Non Jews in Europe did not wear anything resembling a turban and apparently neither did Jews so we start seeing written accounts by 13th century Ashkenazi Jews that the blessing was no longer being said.
A) R. Asher ben Shaul of Narbonne (13th century France) in his Sefer haMinhagot (pg. 141)  recorded that the blessing was not cited in his region:
ומי שעוטר מצנפת כמו שעושין בספרד מברך עוטר ישראל בתפארה שדומה לעטרת, והזכיר ישראל מפני שכינה שהיא שורה עליהם, ולא יתכן שילכו בגלוי ראש ועל כן קשר להם כתרים בסיני לכל אחד, וכן אמרו בתלמוד (קידושין לא א) שכינה למעלה מראשי, ולא כן הגוים. מכל מקום (הוא) משמע שאע”פ שאין אנו מתעטרין במצנפת אנו מתעטרין בכובעין דין הוא שנברך עוטר ישראל אלא שאין מנהגנו לומר כן, ונראה בעיני שהמנהג שלנו שאין אנו מברכין משום דאין כל ישראל מכסין ראשיהם והולכין בגילוי הראש.
Asher recognized that עוטר ישראל בתפארה was an appropriate blessing for the turban because “it resembles a crown” (דומה לעטרת).
We see similar accounts in the 14th century.
B) R. David Abudirham, a resident of 14th century Christian Spain, in his enumeration of the morning blessings in Sefer Abudirham  (1339) skips any version of the head-covering blessing. In a later chapter he wrote :
ועוד מוסיף בגמ’ כשמניח סדינו על ראשו מברך עוטר ישראל בתפארה על שם (שם קג, ד) המעטרכי חסד ורחמים ועל שם (ישעיה מט, ג) ישראל אשר בך אתפאר. והטעם לברכה זו לפי שהיו עוטרים מצנפת כדי שלא ילכו בגלוי הראש. ואמר כאן ישראל לפי שהשכינה שורה עליהם ולא על הגוים. ובכל ארץ ישמעאל נוהגין לאומרה מפני שהם מניחים מצנפת על ראשם, אבל באלו הארצות אין נוהגין לאמרה כי אינם מניחין מצנפת. אבל נוהגין לומר ברכה אחרת שאינה נזכרת בגמרא …
The intention of Abudirham appears to be that in Christian Spain (“these lands”) the turban was not worn by Jews and therefore no headdress blessing was said, unlike in North Africa and the Levant .
While these sources don't conclusively prove when Jews started wearing a hat in Europe, it does say that the European Jewish community had broken with traditional Jewish dress and had actually removed a Talmudic blessing from their religious practice. The sources above indicate that many Jews didn't wear a headcovering at all (not even a kippah!). It therefore makes sense that the blessing would not be re-instituted for "the hat" that is now in common use since the hat was clearly a later use of a gentile article of clothing.
It should be noted that now almost no Jewish communities say this blessing when putting on a head covering. This and all the other dressing related blessings have been relegated to a fixed part of the "morning" service and are now said in synagogues, completely separated from the acts they were tied to in Talmudic times. I have only seen certain Rambam based groups who continue the proper practice of saying this blessing with a turban style head covering.
Jews in Europe (and other parts of the world) were often forced to wear clothes that distinguished them from non Jews. This way Christians and Muslims would be able to tell who was and wasn't a Jew based on their style of clothes. There were many styles of hats that Jews in Europe were forced to wear that were different based on location or time, but many times these articles of clothe were meant to embarrass or humiliate the Jews on top of setting them apart. Here is an example from the 14th Century. Here is another example from Germany in the 13th century. You can see many more sources and styles from going to this Wikipedia article. It seems fair to say that Jews would not want to say the blessing of "crowning Israel with glory/splendor" over an article of clothing they were forced to wear by non Jews in order to humiliate them.
In more recent times Jews were not forced to wear distinctive types of hats or clothing and many took the custom to wear clothes that didn't make them stand out by copying their non Jewish neighbors. Many theorize that this led to the wearing of hats that we see by Hassidic Jews in our days. When this officially began to happen is hard to tell.
The idea of a religious head covering seems to have been a מנהג since ancient times, as seen in Sepher Shemuel II 15:30
לוְדָוִ֡ד עֹלֶה֩ בְמַעֲלֵ֨ה הַזֵּיתִ֜ים עֹלֶ֣ה | וּבוֹכֶ֗ה וְרֹ֥אשׁ לוֹ֙ חָפ֔וּי וְה֖וּא הֹלֵ֣ךְ יָחֵ֑ף וְכָל־הָעָ֣ם אֲשֶׁר־אִתּ֗וֹ חָפוּ֙ אִ֣ישׁ רֹאשׁ֔וֹ וְעָל֥וּ עָלֹ֖ה וּבָכֹֽה
And Daveed ascended upon the Mount of Olives, and weeping as he went up with his head covered, and he went barefoot; all of the people that were with him, each man covered his head and wept as they ascended