On the page directly previous to that, in Luke, Jesus told his disciples that he speaks in allegory specifically so that people won't understand. While that exorcism wasn't explicitly stated as allegorical, I think it was, because of both its placement and the things it says. What Jew would have a herd if pigs? Pigs only serve one purpose for Jews, and that's to represent uncleanliness. They don't keep them around. Then there's the demon saying "we are Legion" - that's very specific. Legions are what Rome uses to subjugate people and extort taxes. A legion isn't anything else. And then the possessed pigs ran into the water and drowned. Where is Rome, compared to Israel? Physically, Rome is to the west, across the water. Legions ran away and drowned in water... That seems to mean the invaders will leave. But there is also a spiritual meaning for both water and the west. The sun rises in the east and sets in the west. Remember the morning star, which rises in the east? It represents resurrection. And the sun setting represents death. To go to the west is to die. Water, meanwhile represents uncreated, unconscious potential. When Jesus walked on water, you're meant to think of Genesis, the Spirit hovering over the water.
In summary, that story means that the invaders are unclean, they are pigs, and they will run down to the west and die, returning their uncleanliness to the water, where they may be remade into something clean. Demons, in this case, could (not saying definitely) be a useful tool of rhetoric - and this is the classical world, so rhetoric features strongly as one of the seven classical liberal arts - the subjects of study for education. I'm not saying it didn't happen - idk - but I don't think the purpose was to tell us about demons.