Primary is a word about rank, and it has always been one. It comes from Latin prīmārius — 'of the first rank' — from prīmus, meaning 'first'. The PIE ancestor *per- meant 'forward' or 'before', and its descendants populate English at every turn.
From prīmus alone we get prime (first quality), primitive (belonging to the first age), primer (a first book), and primordial (from the first order of things). The superlative force of the original Latin survives intact: primary still means 'first and most important'.
The word entered English through scholarly Latin in the 15th century, initially in religious and educational contexts. A primary source was the original document. A primary school was the first level of education. The political sense — primary elections — is American, dating to the 1860s, when parties began holding preliminary votes to select candidates.
The family tree branches further than most people realise. Prince comes from Latin princeps — prīmus + capere, 'first taker' or 'first person'. Principle comes from principium — 'first foundation'. Pristine means 'in its original first condition'. All these words carry the same Latin claim: whatever is prīmus stands at the front of the line.