I think it is also important to consider the pre-existing socio-cultural perceptions of pigs that permeated the societies around the near Eastern region that would have shaped early Jewish and subsequent Islamic perceptions of pigs and eating pork. In the near East in the early Bronze age pigs would have been seen as very useful to the growth of sedentary settlements or for starting new ones as pigs can reproduce quickly, allowing the human population to grow larger by having this readily available food source. In the history of the development of animal husbandry pigs might have even been one of the earliest animals to be domesticated because of the relatively efficient life cycles they have for producing young. Pigs can grow and mature to be able to be a couple hundred pounds at slaughter and be able to produce offspring within a year of birth, plus their eclectic diets allow them to consume a lot of different available food stuffs to allow them to grow quickly. They also need to take up much less space relative to other animals that would need larger grazing pastures, freeing up land for human occupation, as well as other animals or crop growth. Due to these factors pigs are much easier to raise making swine herding a profession that is readily available to many people.
However as larger settlements and governmental organizations emerged in the later Bronze Age they produced more complex social relationships that affected the cultural perception of pigs. In earlier and smaller settlements pig’s consumption of waste would have been efficient to keep the surrounding environment free of pollutants in the form of food waste, trash, corpses of other animals, and feces. However as these communities become larger and start producing more and more waste in all forms this association with pigs eating and often living covered in pollution and mud, due to their lack of sweat glands, can imbue a sense of uncleanliness due to the associated smells and waste materials that surround them. There are even records of ancient institutions in Mesopotamia and the near East that had once had swine herds as part of temple organizations that began to ban the sacrifice or presence of pigs in holy places. Interestingly it seems that a taboo related to dogs also emerged, This was possibly due to the similar nature in which pigs and dogs had been domesticated by humans as scavengers of waste.
““The pig is not fit for a temple,” a Babylonian text reads, because it is “an offense to all the gods.” A Hittite text declares, “Neither pig nor dog is ever to cross the threshold” of a temple. If anyone served the gods from a dish contaminated by pigs or dogs, “to that one will the gods give excrement and urine to eat and drink.””- Lesser Beasts: A Snout-to-Tail History of the Humble Pig, Mark Essig
There is also the social distinction that emerged from the ease of raising pigs going from being associated with the growth of the initial urban populace to being related to growing the urban poor and marginal communities. This was heightened by the fact that with the implementation of taxation and large scale trade by these governing bodies pigs would have been seen as a less favorable livestock animal as they only produce meat at the slaughter. While other animals like chicken, goats, cows, and sheep produced secondary byproducts such as eggs, leather, wool, and milk that could be additionally taxed and traded. So due to pigs being a low source of wealth generation along with them being easier to breed it would have caused the poorer and more fringe communities on the edge of governmental influence and control to have more swine herds which would have interim created a cycle of imbuing them with a lower socio-economic status. This also resulted in the distinction in the diets of the different social classes with the lower classes eating much more pork as it would have been an easily available source of protein while wealthier individuals would have been able to afford to eat more wealth producing animals. This resulted in the taboo of even touching pork in Egypt where Herodotus, in the 5th century BCE , records “an upper-class Egyptian man, after accidentally brushing against a pig, rushed into the Nile fully clothed to cleanse himself”.
The subsequent Late Bronze Age collapse of these larger societies led many of these trade networks and settlements to shrink and disperse. With this migrations of people it lead to the emergence of new communities through ethnogenesis as well as new rivalries between these communities due to this large societal shift. The most important for the early emergence of the Jewish pork taboo possibly being the emergence of the Israelite-Philistine rivalry. The Philistines originated from a multitude of peoples that had migrated from around the Aegean island to the coastal regions of the Levant bringing with them some pigs and an Aegean diet that included pork around 1200 BCE. The first Israelite communities began to emerge out of a possible mix of settled and nomadic Canaanite groups that had moved into the interior highlands in Southern Canaan at the same time. Across these early Israelite communities there is very little record of pork consumption, while for the Philistines there was a high variance in the consumption of pork. With some settlements eating pork at the same low rate as their Israelite neighbors while in other Philistines settlements pigs constituting up to 20% of the animal livestock found. This variance could be up to the greater cultural diversity that constituted the background of the people that would become the Philistines as well as the cultural exchange that would have occurred between these two groups along with the multitude of other communities in the surrounding areas.
This exchange led to certain interesting outcomes to occur by the Iron Age period when the Leviticus pork taboo is possibly dated to have been first written down during the period of the southern Kingdom of Judah and northern Kingdom of Israel. By this time the consumption of pork in many Philistines settlements had decreased to match many communities in Judah, however the consumption of pork had actually increased in the cities in the northern Kingdom of Israel. There is an argument that therefore that the reforming kings and religious leaders of the southern Kingdom of Judah were the ones who began to enforce the pork taboo to create a distinction, based in theology, between them and the Northern Kingdom of Israel. However it could also be seen as an object of assimilation especially as people from the Northern kingdom began to migrate down to the south, the pork taboo could have been a way to define the religion and majority culture of the kingdom of Judah. The subsequent conquests by Alexander the Great and the Romans introduced another social layer and distinction between these expanding empires and the Jewish community. The Greeks and Romans loved pigs, as opposed to the prevailing Israelite view of pigs as being these unclean polluted animals, the Greeks and Romans viewed them as a sign of purity and abundance.
“In Greek mythology, after Jason and Medea kill Medea’s brother, the enchantress Circe captures a piglet from “a sow whose dugs yet swelled from the fruit of the womb,” slits its neck, and sprinkles its blood over the hands of the killers to remove the stain of murder. Similarly, a painted vase shows Apollo holding a sacrificed piglet, still dripping blood, over the head of Orestes, who has killed his mother”- Lesser Beasts: A Snout-to-Tail History of the Humble Pig, Mark Essig
Pigs were the most common sacrificial animal at temples to honor the Greek Gods, celebrate weddings, births, the signing of contracts, they also also just though it tasted great with the physician Hippocrates proclaiming that it was the best of all the meats. These distinctions between Non-Jews and Jews were heightened when the Jewish community began to be heavily persecuted by Seleucid Kings such as Antiochus IV who banned circumcision and sacrificed a pig in the Jewish temple on a newly built altar to Zeus. This was probably the period of time when abstaining from pork began to solidify as a part of this emerging ethno-religious distinction due to this series of persecutions and the new Hellenic and subsequent Roman cultural environments the Jewish community found themselves to be surrounded by.
In Jewish tradition, pork is not any more or less unclean than any other unclean meat. Leviticus 11:1-8 calls out several specific unclean animals--pigs are fourth down the list. Pigs were not used for anything else except maybe leather, and you wouldn't breed a whole animal just for its skin if you were going to throw out the rest of it.
Contrary to popular speculation, Jewish food prohibitions have nothing to do with food safety. They're part of a much larger code of ritual purity, which is sometimes a difficult thing to explain to westerners because we don't (explicitly) do ritual purity anymore. Essentially, purity is about demarking certain times, spaces, and behaviors as different from others. Jewish purity codes have the added function of marking off certain people (Jews) as different from others, and that's primarily where the food laws come in. Jewish tradition delineated pork, shellfish, etc., as unclean because other peoples around them did eat those things, and it was and continues to be a very visible way to set themselves apart.
That's also why pork has become the poster child, as it were, for unclean food in Jewish tradition. As a people, Jews have almost always been a relatively small minority surviving among expansionist empires (I and others discuss that here). By the end of the Second Temple period (so end of the Roman republic/beginning of the empire), there were large non-Jewish populations in parts of Israel, and Jews themselves were spreading into cities across the Mediterranean, so Jewish communities had a lot of contact with non-Jews. There's a lot of emphasis on defining Jewishness in this period, and often that played out as emphasizing Judean/Jewish culture in contrast to other local cultures (the article by Berlin that I cite below shows some interesting evidence of this, not directly related to food). As it turns out, one of the easiest types of livestock to raise for food is hogs. Sheep and goats are valuable for milk and wool, and cows were work animals, plus they take a lot of space, so even though you could eat those animals, and often did during large festivals, meat was a secondary and expensive use. The type of meat most available in the everyday, especially in landlocked regions, was pork, which made it a really easy part of the purity code to focus on. "My tradition doesn't allow me to eat crab" doesn't hit as hard if no one around you is eating crab, either, you know?
Here's that reference, plus a couple of books that address Jewish food practices:
Berlin, Andrea M. “Identity Politics in Early Roman Galilee.” In The Jewish Revolt Against Rome: Interdisciplinary Perspectives, edited by Mladen Popović, 69–106. Leiden ; Boston: Brill, 2011.
Garnsey, Peter. Food and Society in Classical Antiquity. Cambridge, U.K. ; New York: Cambridge University Press, 1999.
Kraemer, David Charles. Jewish Eating and Identity Through the Ages. Routledge Advances in Sociology 29. London: Routledge, 2009.