It’s not stated in HP canon, but this enmity goes a long way back.
The exact reason is never given in the Harry Potter canon, but we can make a guess:
Basilisks can kill you with eye contact. That’s very unusual. I can’t think of any other creatures that can do that (at least in the Potterverse).
Spiders have many unclosable eyes.
The eyelid is mostly found in mammals; a lot of other animals have no need for them. That includes spiders and insects – there’s nothing covering their eyes. So just being in the presence of a basilisk is dangerous – they have all-round vision, and they can’t close their eyes. (On the other hand, a spider against a Weeping Angel?)
But is that enough to make them mortal enemies? That’s unclear.
When Harry and Ron encounter Aragog in the forest, he’s blind, but clearly still scared of the Basilisk. It’s possible that there’s no longer a rational reason for the fear, but has simply become something baked into the spider psyche.
The idea of spiders fleeing basilisks is hardly a new one. In Bulfinch’s Mythology, a nineteenth-century retelling of classical mythology, we find the following passage:
The basilisk was of some use after death. Thus we read that its carcass was suspended in the temple of Apollo, and in private houses, as a sovereign remedy against spiders, and that it was also hung up in the in the temple of Diana, for which reason no swallow ever dared enter the sacred place.
The same passage states other facts about the basilisk that are repeated in HP canon – for example, the red plumage, or being hatched with a chicken’s egg under a toad – but doesn’t provide a reference for this passage.
Bulfinch is supposed to be a retelling of existing stories, so we could probably trace this back into other classical sources, and we might find a reason there. Unfortunately I don’t have time to do that right now – exercise for the reader? :-)