I know - he was a philosopher, fine. But, how did he buy food? Or pay for anything? Was he paid to be a philosopher? If so, by whom? Same goes for other philosophers - was it a full-time job or did they have something on the side?
Like so many modern philosophy majors, Socrates seems not to have been cut out for the world of gainful employment. Although the sources on his early life are scanty, we know that his father was a stonemason, and it is reasonable to assume that he was trained in the same trade. According to a later tradition (not attested until centuries after his death), he actually worked as a sculptor for some time. During the early years of the Peloponnesian War, when he was in his forties, he served with distinction in several campaigns. But by the time he appeared in Aristophanes' Clouds (423 BCE), he was already notorious as a full-time intellectual. As far as we can tell, he had no regular employment for the last two decades of his life, and seems to have spent most of his time wandering around the public places of Athens (always barefoot and dressed in a simple wool cloak), engaging anyone who stood still long enough in conversation. In these years, Socrates made philosophy (or at least interminable discussions of ethical concepts) a full-time job.
At first, Socrates must have had a little money saved up - either an inheritance from his father or the accumulated wages of his own work as a stonemason. The fact that he served as a hoplite in the Peloponnesian War indicates that he was able, at that point, to pay for his own military equipment. He was certainly never wealthy, however, and his proverbially ill-tempered wife Xanthippe (whom he married late in life) was probably so ill-tempered because her husband refused to get a job. At least once, Socrates himself claimed to live in poverty (Apology 23b-c). He didn't starve, however - and this is almost certainly because most of his friends and pupils belonged to the Athenian elite, and were more than happy to support their penniless master.
Some Greek philosophers were even less concerned than Socrates with the tawdry matters of income and employment. Cynics embraced a life unencumbered by possessions, and lived by begging. Diogenes, the best-known of them, inhabited a large clay amphora by the Athenian Agora. Although few philosophers were quite so austere, the ideal of simplicity had a long history. The Stoic Epictetus, for example, despite being a friend of many eminent Romans and the emperor Hadrian himself, was famous for the simplicity of his life.
Many philosophers, however, came from wealthy families, and saw no particular reason to forswear that wealth when they started philosophizing. Plato, a member of one of Athens' oldest and most prominent clans, is one example; Aristotle, whose father was personal physician to the King of Macedon, is another. The Stoic philosopher Seneca was one of the richest men in Roman history, reputed to have a fortune of 300 million sesterces (at a time when most families survived on 500-1000 sesterces each year). Thales himself, the father of Greek philosophy, was said to have good business sense. Once, simply to prove how easy it was to make money, he used his meteorological observations to determine that it would be good season for olives, rented all the local olive mills, and made a killing.
Some philosophers - from the sophists of Classical Athens to the display orators of the Second Sophistic movement - earned money by teaching wealthy pupils. In the Roman imperial era, a few were supported by the four chairs in philosophy (one for each of the principal philosophical schools) endowed by Marcus Aurelius in Athens. But most Greek and Roman philosophers were either independently wealthy or - like Socrates - reliant on wealthy patrons.
So /u/toldinstone has already written an excellent answer to the question in relation specifically to Socrates, but I study Ancient Mesopotamia and in particular science and religion especially in the late First Millennium BCE (around the time that people like Socrates were living) and so I thought it might be nice to talk some about how people that worked in Mesopotamian scholarly endeavors made money themselves as it can perhaps give us a better understanding of how people who pursued these types of scholarly pursuits in the ancient world would have been employed. The picture in Mesopotamia will absolutely be quite different than it was in ancient Greece and to our knowledge there wasn't really a scholarly discipline that remotely looks like Greek philosophy in Mesopotamia, but the Mesopotamians were nonetheless very interested in especially the movement of the stars and the planets and so if we want to extend this question more generally to how people who spent their life doing things that seem to have no immediate monetary gain like watching the stars supported themselves then I think the picture at Mesopotamia is certainly worth discussing.
One very major point to discuss before talking about Mesopotamian "scientific" endeavors is that the entire idea of "science" certainly did not exist in Mesopotamia in any capacity. In the same vein, "religion" would never have existed as a distinct idea and so the vast majority of people engaged in the things that modern scholars identify as precursors to modern "science" were doing so for religious reasons. To the Mesopotamians the stars and the planets were literally their gods and their movements were interpreted as being messages from the gods, "the heavenly writing," and so by far the biggest employer of Mesopotamian astronomers was the temple. The most detailed astronomical record we have in cuneiform are the tablets referred to as the Astronomical Diaries, which include night by night recording of the movement of all the planets during the year as well as different pieces of information about the motion of the moon, coupled with information on the weather, the level of the Euphrates river, some prices for a set of commodities in the market, and even historical information. These regular recordings likely began by around 400 BCE and ended sometime before 100 AD, and the vast majority of recovered tablets are from between 400-200 BCE. The bulk of recovered tablets containing astronomical diaries were compiled by individuals who were employed by the Temple of Marduk, known as Esagil, in Babylon and their job was specifically to go out at night and record the position of the planets and then write those down on tablets which they would use to collect all the recordings onto yearly tablets later. Another temple that was certainly very closely involved in the production of astronomical diaries and where similar tablets have been discovered was the Bit Resh, the temple of the sky-god Anu located in the city of Uruk. Uruk and Babylon were both ancient centers of cuneiform scholarly endeavors and became some of the last bastions of cuneiform writing well into the Hellenistic period when the people of the city and most certainly the scholars themselves would have spoken Aramaic to each other and when administrative writing would have been done perhaps in Aramaic at the local level and most definitely in Greek at the royal level.
As such, the astronomers working at temples would have been paid out of temple stocks and this shows increasingly the strength of the temple institution as a whole in Mesopotamia into the later periods. The temple would have obtained their stock from a number of different places. Part of it would be from donations by people in the city, but likely more of their wealth would come from land that would have been donated to the temple by the king or other senior government officials and those lands would be maintained by slaves also donated by the state. Temples in Mesopotamia would have certainly been exceptionally wealthy but it is probably also the case that the point of this wealth was almost as a "bank" in that if there were issues in the city as a whole such as famine or war the temple could use their stores to help people. At a minimum, it was expected that the wealth of the temple was meant to enrich the "life" so to speak of the god who called that temple "home" (there is no distinct word in Akkadian for temple, the word bitu which is used to refer to temples is also used as the general word for "house" and so temples were simply the "house of ... god"). Their gods were literally statues that they performed specific rituals on in order to allow the spirit of the deity to "inhabit" the statue, and so caring for these physical manifestations of their gods was a large part of the temple's job. They provided daily meals to the gods, and it is likely the case that the physical remains of the "meal" which obviously wouldn't actually be eaten by the statue were a means of payment for temple personnel including the scholars working at the temple. The temple also facilitated the various religious festivals which often involved taking the god on a trip to other cities or parading him about the city, and these could be accompanied by elaborate feasts. The belief was that by providing for their gods in the form of these statues they would keep the god happy and this would in turn bring prosperity and success to the city as a whole. While I do expect much of this wealth was used to improve the lives of the priests themselves and make them personally wealthy, we should not be so cynical as to believe the goal of the temples was to be a personal business for the priests.
Some scholars in Mesopotamia would also have been employed by kings and we can see that this practice most certainly remained in place in ancient Greece. Aristotle, for example, is famously known for having been employed as the personal tutor for Alexander the Great. Kings in Mesopotamia, most clearly evidenced by a massive body of letters discovered from the Library of Ashurbanipal dating to the years around the reign of Esarhaddon and the ascension of Ashurbanipal, personally employed an army of scholars who would help watch the stars and interpret events. The Mesopotamians believed that there were many ominous events that could be inferred from the movement of the stars and the series of celestial omens Enuma Anu Enlil was likely over 70 tablets in total. The scholars commanded a great deal of respect by the king, and they were capable of in effect influencing the actions of the king through these omens. We should not see them as "puppet masters" though who tried to actively control events; the king would check the predictions of his scholars against other scholars at court and if he believed a scholar was lying to him he would at the least imprison that scholar and punish his entire family if he did not execute the scholar outright.
Being a court scholar in Mesopotamia was certainly very profitable though and these positions were highly coveted and moved down through families. The senior court officials often had their children employed if not in their exact position at court at least in other related senior court positions. This was likely in part because of the physical access they had to tablets themselves which contained the omens that made up the entirety of their jobs. They would have jealously guarded their tablets and in later periods they even describe tablets as "secret information" and instruct people not to show them to "one who does not know" on the colophon. Because of this restriction of physical access to tablets, not everyone could obtain the information that would allow them to be a senior court scholar and positions remained in families generally. This would also have been beneficial to the king as it created a reason for senior court officials to be more loyal to him as it was not simply their own livelihood that they risked by being disloyal but also the potential for their children and grandchildren to obtain similar positions in the court. Court officials likely were paid in part by what is referred to as "the leftovers" of the god, which potentially refers to that same food that was given to the statue of the god for their meal that I discussed previously. Eventually the scholar would inherit and be gifted land in the same way the temples were. The king would provide his senior officials with land in the country that they would have slaves maintain for them and that would make them generally relatively wealthy. We have documents with examples of senior military officials buying land or selling land to court scholars, indicating that they did participate in economic transactions.
While this situation may not necessarily translate perfectly to the situation in Greece and certainly does not mirror the way Socrates made a living at all, I think it is interesting to consider how individuals who pursued scholarly professions were able to live. As we see, being a scholar was certainly possible likely as early as writing was a thing. As soon as written texts which contained useful knowledge appeared and became increasingly standardized, there were people making a living by using the knowledge they obtained from reading those texts.