I was told this but can’t source it but it certainly does explain why Muslims and Jews don’t eat pork and why they consider it to be a “dirty” animal: pigs were used to clean up/process dead bodies. After big battles, lots of dead bodies would be lying around which can spread disease quickly. The solution was to have pigs eat those bodies. Certain religious groups were not too keen on the fact that, by eating pigs, people were indirectly eating other people.
I know they always say the no pigs thing is because they roll around in their own poop all of the time but pigs are hardly the only farm animals that do that.
You may be interested in my older answer to the question:
The long and the short of it is, though modern scholars have multiple theories about the origin of the taboo (I briefly list some of them), no one knows for sure why this taboo was adopted by the ancient Israelites (and from there, by Muslims and other groups).
Judging based on pig bones, the taboo on pigs as polluting seems to emerge in the Iron Age as the Israelites were emerging as a separate people (see the book Purity and Monotheism, for example). This is likely earlier than, I learned this year, than the kosher taboo on certain kinds emerged or at least become widespread—this article argues that likely this practice was widely adopted only in the Second Temple period. The pig taboo may be the only food taboo that was novel to the region that emerged in the Iron Age with the rise of Judaism/Israelite cultic practice (the other food taboos besides pig and certain kinds of fish don’t seem to change much how the people in the area were already eating), but we will never know exactly why it was adopted.