I seriously doubt a realistic answer to this is possible, as we would have to understand what separates the genesis of intelligence from the genesis beneficial behaviours and actual civilisation from "mere" intelligence. However, I tried to think up some ideas that might be productive for science fiction.
Firstly, one way to drive a social structure in the most primitive sense (consider ants or bees) would be diversification within the species - such as exhibited by Queens, workers, drowns. Yet, one might turn this into a hen and egg problem.
I don't think the restriction to a parasite of any order is crucial, but I will stick with it. Let's say our first order parasites Antrasi are a species of fungus living on the hairy parts of mammalian skin. Especially heads. Our second order parasites Betrisi were originally fairly standard lice-like animals feeding off fungus. Over time they adapted to the specific Antrasi fungus.
The problem with Antrasi is, that, after about 6 months, it destroys the skin, so that it kills itself. Luckily, there exist different types of it. If they infect a head in succession, they restore the Ph, so that the skin remains intact and they can keep living. The problem is, that such a transition is unlikely to occur through natural dissemination of Antrasi spores. 238
Here Betrisi come into play.
The Betrisi-Scout is a subtype capable of wide range flight. Every 6 months it flies from head to head, seeking sleeping individuals infected with suitable fungi. The worker is in charge of harvesting large quantities of fungi and transportation to the other host head. It also produces suitable chemicals to facilitate quick growth of the newly displaced colonies. Over time Betrisi might evolve complicated behaviours, just like bees or ants. How they might transition from these primitive stages to intelligence, is an insanely difficult question.
If one is willing to be even more unrealistic, one might endow Queens with feromones inducing mutual attraction in suitable (super) hosts. That would help bringing them closer together!
Obviously, if one already believes in intelligent parasites, it is trivial to show how all manner of cunning and cooperation (between colonies) would aid them. The trouble is, you asked how they would become intelligent and that is certainly a Noble Prize question. It is not entirely clear to me what qualifies as swarm intelligence but a high degree of communication between colonies is obviously desirable. I want everything to be tightly synchronised. Ideally, I want all human couples determined by this rationale! 197