Additionally to tree's explanation, it might also origin from primary meaning something like "essential", meaning it's a mandatory level of education for all children, while secondary school might be more optional, "on-top". This idea could come from older times, when children only had a few basic years of school before starting to work.
Secondary is word that means coming after the first/later/second.