That does not preclude an evolutionary pathway from indirectly forming around incidental hazards.
Consider a disease that kills everything incapable of resisting it. The survivors are incidentally immune to the disease, regardless of the reason they possess the trait, and only because everything else was destroyed, and so now their descendents fill the vacuum the disease created.
It also means that the subsequent generations get to carry forward any odd traits that their ancestors displayed, whether they make sense or not, simply because there's room for baggage to slip through. So, it would not be unreasonable to consider that the intelligence is incidental to a hypothetic disease immunity, rather than an essential survival characteristic. The reproducing survivors just happened to carry both traits, but only needed one.
I don't think it fits this parasitic ant fungus scenario, because the fungus is not an invasive extinction level pandemic species of fungus, rampaging so violently throughout ant populations that it creates a bottleneck that eclipses substantial portions of ant species. The fungus is limited to small regions, compare to the full range of ant activity, worldwide.
But, it's not unreasonable to consider ideas that don't intuitively correlate to the observed result, at least in terms of biological evolution.