We first ignore potentially unprovable reasons like translation errors (remember that you are virtually never reading a primary source) or persistent inaccuracies and inconsistencies ancient historians tend to experience, although we should not forget that these reasons are nonetheless valid and possible.
We then establish how the hastati, principes and triarii are used in the standard manipular legion, which is the particular form of the Roman legion that is the subject of your question. This is for those who may not know it, and will be the basis against which historically known, differing usage of these terms can be compared against in reference.
The names are transliterated to mean "spear-bearer", "main-liner" and "third-ranker" respectively. The hastati are so named because they were equipped with spears and operated as a phalanx (although every Roman melee infantry soldier were similarly equipped at the time) up to the Samnite Wars, when the hastati and principes abandoned the phalanx and adopted the Samnites' more irregular way of combat, becoming the earliest version of the time-honoured legionary we recognise today. Subsequently, the name hastati carries only historical meaning.
The names principes and triarii, in contrast, carry practical meaning as to their tactical function specified in the triplex acies (triple battle order) system.
- The lightly-equipped hastati, young and full of vitality, serve as relatively light infantry, responsible for the first melee and charged with wearing down the enemy's strength and stamina. They will then retreat behind the principes.
- The principes ("main liners"), will then close ranks and form the main battle line. These battle-hardened veterans are the true hammer of the manipular legions. Heavily-armed and still fresh, they are perfect for charging an enemy that is worn down. It is their responsibility to win the battle.
- The triarii ("third rankers") stand behind the other two as the third line, not intended for routine tactical use since the battle is intended to end at the principes' line. If the main line does break, however, the principes will retreat behind the triarii, who will then close ranks, form a phalanx and advance. A wall of highly-equipped, highly-veteran hoplites are effective at buying time for the hastati and principes to retreat in an orderly manner, or to reform battle lines for a second engagement.
For this reason, hastati has always been considered to mean the first line, principes the second line and triarii the third line in the standard manipular legions. This is the default order, and any description you find to the contrary is inaccurate for a manipular legion as far as standard tactics go (and the Romans love being systematic). Roman generals are not incapable of forming up non-standard formations, however. When particular battles call for it, there have been examples of both hastati and principes forming up a single unbroken line (don't quote me on it, if memory serves one such example is a certain African battle fought in the Punic Wars, possibly a major one). After all, Rome demands victories, not blind obedience.
Besides different battle formations from the traditional, another possible reason for the discrepancies you mentioned would be in the cohort-based legions of the late Republic and early Empire. Each of the ten cohorts are still sub-divided into three maniples of two centuries each, still named in the old manipular way. However, with standardised state-sponsored equipment, these naming conventions are only significant as far as serial numbers go. Their ordering when forming up for battle is still in the same order as before, although they can just as easily be shuffled around without much consequence.
Sources (you can refer to these for learning about the Roman legion's composition as it evolves throughout the centuries as well):
They may just be Wikipedia links, but personally I have been reading about Roman military history since late childhood, and these articles give quite a well-detailed treatment of the subject with new insights too, especially on the matter of Roman cavalry. I would judge that these are good material for the casual reader, and a good starting point for researching into other publications for more formal studies.