I should check a couple of book to be sure that I remember all right, but I recall that when in 1731 Antonio Farnese, Duke of Parma, died, he named in his will as his sole heir his niece Elisabetta. Elisabetta in turn ceded her rights to her eldest son, Infante Carlos of Spain, who succeeded as Duke of Parma and moved there in 1731. Carlos therefore inherited the Dukedom of Parma and all the other titles of the Farnese family as well as all the estates and art collections.
In 1734 Carlos became King of Naples and Sicily; he relocated to Naples, bringing with him most of the art collections. Later the 1738 Treaty of Vienna recognized Carlos as King of Naples, but he had to cede the Dukedom of Parma to Austria. He still however kept the rights to the other titles and estates inherited by the Farnese family.
In 1748 with the Treaty of Aix-la-Chapelle the Dukedom of Parma was ceded by Austria to Spain, and King Fernando VI in turn ceded Parma to his half-brother Felipe, who became Duke Filippo I of Parma and was the ancestor of the Bourbon-Parmas.
This explains why the bulk of the Farnese inheritance and the titles of the Farnese family passed to the Kings of Naples (and later of the Two Sicilies).
The inheritance included the title of Duke of Castro, the ownership of the Farnese Palace in Rome (where King Francesco II lived in exile; later the Palace has been sold to France, re-aquired by the Italian State and leased for 99 years to France; it now houses the French Embassy in Rome) as well as the art collections. To host the art collections of the Farneses, King Carlo decided to build the Royal Palace of Capodimonte.
I hope to have explained all right and clear.