Prince Charles Edward wasn't the 2nd Duke of Albany, because Prince Leopold wasn't the first Duke of Albany.
There have been Dukes of Albany since at least Elizabeth I's reign. Lord Darnley, husband of Mary Stewart (Queen of Scots), was an early Duke of Albany, if not the first one. If all of this was strictly hereditary, then his Duke of Albany title would have gone to the English crown when James I/VI came to the throne in 1603.
Anyway, Charles Edward was stripped of the Albany dukedom by George V in the title overhaul after WWI. The title reverted back to the monarch's control. That's why when Prince Edward married Sophie, one of the titles under consideration was the Albany one.
That is not entirely correct. The creations may be confusing, but here is a brief history:
The title Duke of Albany was
first created in
1398 for Robert Stewart, 1st Duke of Albany. Its
second creation was in
1458 (for Alexander Stewart, 1st Duke of Albany). The
third creation happened in
1541 (for Arthur Stewart, 1st Duke of Albany). The
fourth creation was in
1565 (for Henry Stuart, King-Consort of Scotland). The title was re-created for the
fifth time in
1604 (for Charles Stuart, and merged with the Crown upon his accession to the Throne). The
sixth creation happened in
1660 (for James Stuart – again, merged with the Crown upon his accession to the Throne).
<....> From this point on, the title of Duke of Albany was usually accompanied with the title Duke of York and York were: Ernest August, 1st Duke of York and Albany (created in
1716), Edward Augustus, 1st Duke of York and Albany (created in
1760) and Frederick Augustus, 1st Duke of York and Albany (created in
1784). <...>
In
1881, the title Duke of Albany was re-created separately for the seventh time: the new bearer of the title was Prince Leopold, 1st Duke of Albany, who was succeeded by his son (born after his death) – Prince Charles Edward, 2nd Duke of Albany.
The title was suspended under Title Depravation Act in 1919. Nevertheless, it still does
technically exist and should Prince Charles Edward’s descendants apply for restoration of the title, the next Duke of Albany will be Hubertus Richard, Prinz von Sachsen-Coburg und Gotha (the great-grandson of Prince Charles Edward).
I know it may be confusing to understand why there were so many 1st Dukes of Albany if the title had existed since 1398.
Think of it this way: whenever a title was merged with the Crown or whenever there were no legitimate successors of a title, it is upon Sovereign’s discretion to recreate the title: technically, it is a new title with an old name.
Similarly, the easiest way for Prince Edward to become a Duke of Edinburgh is the following: they will wait till Charles succeeds to the title as the eldest son and Heir of the Duke of Edinburgh and upon Charles’s accession to the throne, it will be available for re-creation (as it will be merged with the Crown). If this scenario comes true, Edward will be 1st Duke of Edinburgh (of the new creation), despite the fact his father and elder brother were holders of the title as well.
I haven't been aware that "Duke of Albany" was ever considered for Prince Edward, and I can't see how it could have been: as I mentioned, the title was suspended, but nevertheless, it still exists. .
Of course there are rules for inheritance of titles, but rules can be amended. Show me the British law that states the title "Prince of Wales" can only be given to the heir to the throne.
For heaven's sake, in the past, countries have gone "shopping" around the royal houses of Europe for kings, so who gets which title is flexible at the very least. That's the interesting aspect of all of this!
I don't think England/Britain has ever 'shopped' for a new King. Of course, titles can be flexible: during the War of Roses, they had a new Prince of Wales, King and Queen about once every year, if not month. However, the flexibility was still within traditions and laws: whoever ‘won’ the Crown at the given point, was the King and his Heir Apparent was The Prince of Wales.
The title "Prince of Wales" is
always given to the Heir Apparent of the Monarch. There has never been an exception, and I doubt there ever will be.