Sardinia was a part of the Roman Empire. When The Empire started to collapse Vandals from Africa raided and occupied it for a short time (456-534 A.D.) When Byzantines (Eastern Roman Empire) reconquered it in 534 it was officially Byzantine. In the 9th Century, the Arabs began conquering Sicily and left Sardinia to defend itself. Therefore the local government gained control of its own civil and military powers instead of the Byzantines, granting lots of autonomy. In order to defend better against Arab and African raids, the Sardinian government gave all civil and military duty to 4 lieutenants. In turn, they all controlled their own pieces of land and named themselves judices (Sardinian for king). Granting more autonomy than they already had. Because of the differing levels of autonomy you can debate when they actually gained independence from Byzantium but it became official in 1258, 1259, and 1288 when 3 out of the four kingdoms fell to Pisa. The Forth remained Autonomous until 1420 when the entire island was taken by Argon who was then integrated into Castille, forming Spain.
Source: My own History class, BUT I found on the actual Sardinia website pretty much everything I just said: