Actually, their claim is supported historically, and legally. They might be going by technicalities, but so are other countries in the region, and so does the US, for example in claiming Navassa Island (Haiti disputes the claim) and Baja Nuevo Bank (claimed by Jamaica, Nicaragua and Columbia). It's not like China is alone in having disputed territories. The US even has unsettled border disputes with Canada and waters off the Mexican coast.
The source of the claim is that in 1884, France and China went to war over control of Tonkin and Annam (today Vietnam). China lost the war, and the region fell into the French Sphere of influence. In 1887, the Sino-French Treaty formally forced China to relinquish their sphere of influence in those regions, in exchange for the Spratlys and Paracels, which states:
The isles which are to the east of the meridian of 105° 43' longitude east of Paris, which is to say of the north-south line passing through the eastern point of the island of Chagu [Tch’a-Kou or Ouan-chan (Tra-co)] and forming the border, are similarly assigned to China.
Translation of the treaty can be found here:
1887, Tonkin Border - France | china's external relations - a history
Paris is located at 2°21' longitude, so this corresponds to 108° 4' E of the Prime Meridian:
In any case, no nation laid claim to the Spratlys before then. However, in 1883, when Germany sent explorers to the Xisha and Nansha Islands, they were stopped after a request by the Qing Government (
source). Later on, successive Chinese governments developed the largest islands in each of the island chains, namely Woody Island (currently administered by the PRC) and Taiping Island (currently administered by the Republic of China). The claim here is that since both of these islands are clearly not fully submerged at high tide, and capable of supporting a permanent human presence, they are entitled to a 200 nautical mile EEZ. Woody Island has a population of about 1400 military and civilians, while Taiping has a population of about 600. As they are capable of supporting life, the contention is more about how these would overlap with other competing claims in the area. If you draw the 200-mile radius around each of these islands, it comes very close to approximating the nine-dash line.
The situation is made more complicated by the fact that Taiwan (formally called the Republic of China) also claims them, and that China claims to be the successor state to the ROC. In fact, Taiwan claims Woody Island and China claims Taiping, the islands being occupied by the "other China". This is similar more or less to how some territories claimed by the Confederacy were later re-incorporated into the Union after the Confederacy lost.