score:7
When I first asked this question I was anticipating a quick answer, but it seems that is problematic.
I will try to answer it myself and then progressively improve the answer based on comments and such.
Transylvania had some autonomy within the Kingdom of Hungary before the partition of 1526–1541, which may have played a role in the creation of an autonomous polity after the partition.
There was the title of "Duke of Transylvania", which should qualify Transylvania as a duchy, but that was granted only four times, to either a son or a brother of the king of Hungary.
The normal rule was the Voivodeship of Transylvania, where the ruler was the vajda (from the slavic voivode, literally "war-leader"), who acted as high-ranking royal official with wide-ranging administrative, military and judicial powers. But he was just the representative of the king and appointed by him, like a governor, while the autonomy of some regions and towns within Transylvania were freedoms grated by the king that limited the power of the Voivode over them.
Transylvania was not as much an autonomous region of Hungary as a region with more different autonomous powers and freedoms than the rest of Hungary. First, there was the relative autonomy of Hungarian nobility in relation to the king. The king limited the autonomy of the seven Transylvanian counties by the power of his appointed voivode, who was one of the greater nobles of Hungary. But some regions (like the Székely) and (especially German) towns enjoyed greater freedom in relation to the nobles as well as the royal power. These three elements formed the Unio Trium Nationum, an alliance of the privileged classes against the peasants (no matter their nationality). And then there were the Romanian and other Christian Orthodox populations, mostly peasants, that had their (very local) religious autonomy - or rather "heterogeneity" - (albeit at the expense of any political rights).
This above map roughly illustrates the situation - a more detailed one here.
As stated in the Wikipedia article linked above: "Because of the gradual disintegration of the medieval Kingdom of Hungary in the 16th century, the last voivodes of Transylvania, who came from the Báthory family, ceased to be high-ranking officials. Instead they were the heads of state, although under Ottoman suzerainty, of a new principality emerging in the eastern territories of the kingdom. Accordingly, Stephen Báthory, the voivode elected by the Diet of the new realm, officially abandoned the title of voivode and adopted that of prince in 1576, upon his election as King of Poland."
But the semi-independent Principality of Transylvania should not be seen as the result of a separation from Hungary, as much as the result of an effort of Hungarian elites to safeguard some autonomy against the Ottoman but also Habsburg power.
John Zápolya, the last Voivode of Transylvania within the unified kingdom and the first independent ruler of Transylvania, acted in the latter case as a King of Hungary. His intension was to act as a conservator of the Hungarian crown, a title which was successfully disputed to him by Archduke Ferdinand of Austria, the late king's brother-in-law and brother of Holy Roman Emperor Charles V.
The separation of Transylvania from the rest of Hungary after the defeat against the Turks is partly the continuation of a previous autonomy, but much more the new result of the balance of power between Habsburg, Hungarians, Polish and Turks.
What aligned for a while the Principality of Transylvania with the two Romanian principalities of Wallachia and Moldavia were military and geopolitical reasons which determined them all in the same way and forced them to play a double or even triple game between Poland, the Ottomans and the Habsburg.
The Archduke Ferdinand anticipated that an independent Transylvania would be tempted to rally with the Turks in order to keep its autonomy, and this was confirmed by the future state of affairs. On the other hand, Trasylvanian rulers seemed to have considered the Habsburg rather than the Ottoman as the main menace, against which they used Polish as well as Ottoman influence, and even adopted Calvinism. They anticipated in a way the fact that a full victory of the Habsburg against the Turks would lead to the full integration of Hungarian lands into the Habsburg empire. This was confirmed by the fact that the collapse of Ottoman power in the region with the Treaty of Karlowitz in 1699 lead to Rákóczi's War of Independence (1703–11) and the end of the relatively independent principality.