This is a copy-paste of a previous answer of mine, but with a bit more clarification.
First off, the two aren't mutually exclusive. Occupational surnames are hereditary nowadays: Smith, Cooper, Taylor, Carter, Miller, etc.
But what I assume you're asking is simply: When did surnames become hereditary and not directly related to a person's occupation?
The answer to this is: It began after the Norman Invasion in 1066, and wasn't entirely fixed in England until the mid-1500s, though in most parts of England among most people, surnames were fixed by the early 1300s. It happened in France about the same time, while in other parts of Europe, it happened at different times, with a lot of Europe making the switch when baptism records became mandatory by the Catholic church and then protestant churches at the end of the 16th Century. But some places didn't make the change until later: the Netherlands switched in 1811 when under occupation by Napoleon, who ordered a civil registration; Sweden didn't make the switch until later in the 1800s, with some Swedes still using patronymic surnames into the early 20th Century; and Iceland has never made the switch, with native Icelanders still using a patronymic form of last name, instead of fixed surnames. Russia and other parts of Europe, too, were later to adopting fixed surnames than England and France.
In the rest of the world outside Europe, it happened at different times as well, but I can't answer that very well, and you'd probably have to ask about a particular country/area specifically to get a solid answer.
Onto my copy-paste:
The "surnames" you're thinking of emerged around the time of the Norman Invasion of England in 1066. But that's not the only kind of "last name" Europe has had. There are three kinds of "last names" in European history: bynames, patronymics, and surnames.
"Bynames", also called "epithets", came first. This is the kind you see in the names "Alexander the Great", "Richard the Lionheart", "William the Conqueror" and his wife "Matilda of Flanders". These weren't confined to the upper classes. By the time of the Norman Invasion, the lower classes were using them, too. The Domesday Book, written in 1079, is filled with names like "John the Smith" and "William of Oxford" and "Richard, Peter's son" and so on. The difference between a byname versus our "surnames" or "patronymics" is that they usually didn't get passed down for more than a generation. "John the Smith" might be father of "David on the Hill" and "Harry the Baker" and "William, John's son".
But it was truly a "last name" because once you had one, you had it for life, unless you immigrated somewhere else or became famous, which, as a peasant, were just about the only ways that your byname would ever change. But normally, once the local lord taxed you as "John the Smith", you'd be recorded as "John the Smith" ever after. Likewise, it was fairly common that, for any of your family that lived on the land of the same lord, they would keep the same last name that their father had, so they could be inherited to some degree. "John the Smith" almost always would have taught his sons how to smith, so any son that stayed on the manor would also be a smith, and thus, still get dibs to the last name "Smith", though this wasn't compulsory. But since just about everyone had ten kids back then, some of the sons would end up leaving for available land on other manors, and if that manor already had a family taxed as "Smith", then the new tenant would end up being forced to adopt a different last name.
The second kind of "last name" was patronymics. Under patronymics, your father's first name became your last name. If your father's name was Donald, and you were Scottish, your last name became "McDonald". If you were Dutch, you'd be "Donaldsen". If you were Russian, you'd be "Donaldovich". But your own son wouldn't keep this same last name. If your name is John, you'd be "John Donaldsen", but your kid would be "______ Johnsen". You'd have different last names.
Under some patronymic systems, you'd have a second last name as well. This was called a "cognomen", which worked exactly the same way a "byname" did, except it was a second last name, not your only last name. But it was used more like a modern middle name, because you'd only mention it if you needed to clarify between two "John Donaldsen"s or whoever.
The third kind of last names are "surnames" or "fixed surnames" like we use today. There is some evidence that fixed surnames had been in use in modern France and Ireland before the Normans invaded England, but not for long--probably not much more than a couple generations. They were adopted in England and Scotland not long after the invasion, replacing the "byname" system that had come before.
The Normans came over with bynames. The difference this time is that the sons of these Norman nobles kept the same byname as their fathers. And their grandsons kept the name too. Within the next couple centuries, "fixed surnames" became mandated on most manors across England. As to why, I have never seen any direct historical evidence, though it's generally thought that fixed surnames made it easier for lords/governments to keep track of taxes, generational debts, and landholdings of their peasant tenants.
By the early 1300s, most people living in England, France, and much of Scotland and Ireland, were using a fixed surname. For example, a guy named Robert Chaucer was born in the late 1200s, and his grandson was named Geoffrey Chaucer, born in 1343 and later author of Canterbury Tales. Geoffrey's son was, in turn, named Thomas Chaucer. The surname was "Chaucer" in the 1200s, and was still "Chaucer" in the 1400s.
This book contains documents from the 1100s and 1200s relating to the King of Scotland. It is full of surnames that are still in use today, usually preceded by "of" or "the".
Many English surnames still had "of"s and "the"s and "at"s in them until the 1300s. This is once again exemplified by Geoffrey Chaucer, or, rather, his wife. Her name is usually rendered as Philippa Roet ("Philippa Red") but her father's name is usually rendered as "Paon de Roet" ("Paon the Red"). During the Hundred Years' War, these articles/prepositions fell out of favor so that we have "John Smith" instead of "John the Smith" and so on.
At the same time this "fixed surname" system emerged, competing patronymic systems emerged throughout Europe. One by one, they fell out of fashion, until only Iceland has preserved the tradition.
Also of note are "Roman names", which are something like patronymics, except that instead of being your father's name, it was a "clan name". It was the name of a distant ancestor, so you shared a last name with a large chunk of Roman society. "Roman names" date as early as the 700 BCs, and were still in use in the 600s AD, before they fell out of favor in place of true patronymics. I'm not an expert on Roman names, but as far as I know, they were not universal, and many Roman peasants never used them, mostly using a "byname" system instead.
So, to answer your question: If we're only talking about Franco-English style "fixed surnames" as being "hereditary", then they've been around since about the 1100s in England, France, Ireland, and Scotland, and mostly universal there by the 1300s, but not completely universal until the early 1600s. From 12th Century England and France, they then spread throughout Europe over the course of the next 800 years so that now only Iceland still uses them.
But there was also a hereditary element to the older "byname" system which has been around since antiquity, though a single family would rarely see all the males in the lineage have the same surname for more than a couple generations, as men moved from one manor to another to take up land.
And if patronymic names are included as "hereditary", then they've been around a bit longer than fixed surnames have been, too.
But when would it have been that someone named "Smith", "Cook", "Baker", "Tanner", "Fisher", etc., didn't actually have that occupation but still used the name? For most people in England, it happened sometime between 1100 and 1600, and it varied from family to family, and manor to manor. It's also possible it happened on occasion before then, with John Smith's son staying on the same lord's manor, and keeping the surname "Smith" as far as the lord's tax collector was concerned, even if the Smith son ended up making his living by some other occupation during most of his adulthood.
It should also be pointed out that, even among people engaged in smithing, or tanning, or baking, or whatever, it wasn't compulsory to use an occupational last name. Even in non-patronymic societies, like England, there would still be patronymic bynames, which weren't strictly hereditary, but did reflect the name of the father: Johnson, Robertson, Jones, Andrews, Michaels, etc. And there were also topographical surnames that reflected some physical feature of where the person lived: Hill, Banks, Meadows, Wood, Green, etc. There was hair color, too: Black, Brown, White, Grey, Rudd/Reid. And then people immigrants from outside the county would often be given habitational last names reflecting their place of origin: Washington, Montgomery, Whitby, Redford. There was no particular rhyme or reason why one family would be be occupational, and another something else, except that the lords tried not to tax more than one family with a single name. So one John would be "Smith", another John would be "Hill", etc.
Sources:
The History of the Norman Conquest of England
English Surnames: Essays on Family Nomenclature
The World's Great Classics: The History of Europe In the Middle Ages