Unlike the Hastati and Principe, the Triarii were spear based and they also the oldest veteran elite troops. So did they initially fight with the sword and then go to the spear (and if so why) or were they always trained in the spear and were not deployed until they were old?
Disclaimer: this answer is not based on literature (primary or secondary), but on the wiki page you have linked, and some general information about Republican Rome.
In the time of the Roman Republic, the professional legions if the Empire did not yet exists. The legionaries were citizen- soldiers: farmers and craftsmen who enlisted for specific campaigns. There was little centralized training, and everyone brought his own equipment.
Early on the Roman citizens were sorted into classes, according to their wealth. This determined the type and quality of armour they had to provide. The triarii where the wealthiest class that still fought on foot. They carried hoplite armament, and therefore their primary weapon was always the spear. They probably had swords, but only as emergency self-defense, coup de grace weapon... etc (note: at this time the romans had not yet adopted the famous gladius.)
With time (and endless wars against the Samnite, Etruscian, Greek, etc...) the army changed. Tactical and strategical mobility grew, and the junior ranks started to carry the "trademark roman weapons" scutum and pilum. It was probably among the triarii where the phalanx tactic lasted for the longest, but by the Second Punic War the wealth-based distinctions among the citizens capable to legionary service were largely abolished: the triarii became the oldest and most experienced soldiers. So they did at first fight among the princpe and hastati in the javelin and sword manner, and were moved to the triarius ranks when they became veterans.
You have also asked the why: Giving the veterans spears had numerous andvantages. Their experience made them less likely either to rout or to charge prematurely, making them ideal as heavy reserve infantry. And they had to run around less, their lessened virility (compared to young men) caused less problems. And since were only lead into action in the case of imminent defeat, their survival chances were probably better. As they would in high percentage have families to care for, them being the reserve lessened the chance of to much orphans and widows being produced.
If you consider that the Roman army was originally a hoplite based army with a separate unit of skirmishers then the triarii were the last remnants of this system.
There are a couple of instances of legacy ideals within the Roman army maintained for tradition. A simple one is the Italo-Corinthian helmet. This was a helmet which originated in the classic Corinthian helm worn by hoplites. A habit of earlier wearers was to wear this helm perched on the head when not in use, presumably for comfort. Later this look was retained in a smaller helmet which was the Italo-Corinthian.
Another example is the retention of Greek style armour along with the sword worn on the left remaining for officers while the rank and file adopted the newer forms of armour and wore their swords on the right.
So the triarii represented one of the last links with the old hoplite past and were a last line of defence hence the expression res ad triarios venit [it's come to the triarii] meaning having to go all in or lose. They were used to defend the camp and at least by the 3rd century it would seem they were not expected to fight. Originally looking like hoplites, by the end of the 2nd century bc they were equipped the same as the first two lines with the exception of being armed with a spear instead of sword. Another legacy from the old hoplite system was the name of the first line, the hastati. The hastati derive their name from the hastae (spear) that they carried.
One way to look at the triarii in this period is a ceremonial type unit armed with obsolete equipment. So regular soldiers once they came of an age would transfer to this unit and then learn the spear drills and formations required of it.
After the Marian reforms of 107bc they disappear and their place as the third line of defence is taken by standard troops armed exactly like the first two lines.