According to Live Science, experts are still baffled as to how a fungus called Ophiocordyceps unilateralis can take command of an ant's brain, turning it into one of the walking dead and guiding it to the perfect spot to spread more spores... which it does by exploding out of the ant's body.
A 2009 study published in American Naturalist revealed that the ants, once infected by the fungus, will journey precisely toward certain plants near the forest floor – a location where the conditions are best for the fungus to reproduce – and even latch onto the leaves just before dying, in order to provide a secure spot for the fungus to spread. This is all happening while the fungus is busy digesting the ant from the inside out.(Source)