1000 years ago, Cornwall was a quasi-independent principality only loosely tied to the rest of Anglo-Saxon England.
During the Norman Conquest, William the Conqueror seized huge swathes of land, and used the money to fund his government. Cornwall was one of these conquests.
The Monarch continued to hold large amounts of land and derive revenue from it. The idea, not always (but sometimes) successful, was that as a result of these revenues, in peacetime, there would be no need for taxation at all to fund the government. In war, it would at least be a substantial subsidy. It was the origins of the Crown Estate.
For the next 600 years, lands changed hands between the Monarch and members of the nobility for various reasons. Cornwall first became important in this regard when Henry III gave it to his brother, Richard of Cornwall in 1225 as a 16th birthday present (!) Richard’s use of ancient tin-mining in Cornwall made him extremely wealthy.
In 1300, Richard’s son died without an heir. The Duchy lands were largely forgotten as part of the Crown Estate for nearly 40 years until Edward III re-created the Duchy of Cornwall from these lands as a gift for his son, the Black Prince, by charter in 1337.
Since then, the Duchy of Cornwall has passed to the eldest son of the Monarch who is heir to the throne, to generate an income for him (if the eldest son is not the heir they would not become Duke of Cornwall).
It should be noted that throughout this period there was little if any distinction between monarch and government. These lands didn't belong to the various kings and dukes in any personal capacity, they belonged to the titles they held.
During the 1600s, starting with the Civil Wars in 1642 and ending with the Revolution of 1688, the Monarchy’s control of the politics collapsed and was replaced with Parliament. The King was to “govern” (in rather limited way) using the revenues of the Crown Lands.
This worked well enough until the reign of George III (1760-1820) who was unwilling live on the revenue provided by the Crown Lands. He therefore gave these lands to Parliament in return for payment of a fixed Civil List.
George III was, however, insightful enough to keep some of the Lands for his use and the use of his family. In particular, the Duchy of Cornwall would continue to pass to the eldest son of the king, and would not be surrendered. Neither would the Duchy of Lancaster. Parliament was, bluntly, conned out of the most valuable parts of the Crown Estate.
Again, it should be noted that the king didn't surrender personal property in return for the Civil List. This was a surrendering of property by one branch of the state to another.
Regardless, since then, the Crown Estate has been operated effectively as a government department, generating a revenue for the government to offset the need for taxation- that was, after all, the point of the Crown Lands going back to the Norman Conquest.
The Duchies of Lancaster and Cornwall have remained independent of the Crown Estate. The revenues go to the Monarch and his eldest son respectively.
How does the Duchy of Cornwall work?
The eldest son of the Monarch and heir is the Duke of Cornwall. If there is no eldest son who is heir, the Duchy is vacant. So for instance, if Prince Charles were to die before the Queen Prince Andrew would be the eldest son, but would not become Duke as he won't be the heir (which will be William). In these circumstances it remains part of the Crown Lands. This is very common - for about half the time since the Duchy was created there has been no Duke. Quite often the Duke was a minor so the Duchy was administered by the Crown.
The Duke cannot pass it on to his children. If he dies without becoming king, the Duchy is vacant. This is also common- there have been 23 Dukes of Cornwall, but only 13 of them ever became Monarch. Indeed, some 16 people have since then become Monarch without ever having been Duke of Cornwall- a majority of Monarchs, therefore, were never Dukes. In fact, the last accession of a Duke of Cornwall to the Crown was in 1936 as Edward VIII.
The Succession to the Crown Act 2013 does not affect the Duchy. The Duchy can never pass to a woman, for example, being the “only” daughter of the Monarch. Elizabeth II was never the Duke of Cornwall (for no reason other than that she is a woman), and indeed the Duchy was most recently vacant between 1936 and 1952 because of this.
On average, a Duke of Cornwall is Duke for just 18 years. Prince Charles, at 62 years, is the longest standing Duke of Cornwall and has been since 2012. George IV (58 years) and Edward VII (60 years) came close.
The Duchy is both a part of the Crown Lands and simultaneously distinct from it. It does not follow any of the usual rules of private property. The Duke could not sell it or give it away outright. He could not leave it in his will.
If Prince Charles was pre-deceased by Princes William or Harry (or if neither of them had been male), the Duchy would be part of the Crown Estate until Prince George became king and had a son. The Revenues would be passed to the government, not to a member of the Royal Family at all.