A major factor for viewing wetlands negatively is because of disease. Mosquitos famously love swampy and marshy environments and are carriers of dreaded diseases such as malaria, dengue fever and yellow fever. Of these diseases, malaria is the one that has done the most damage for the image of swamps and marshes everywhere. Today, malaria has a reputation for being a tropical disease, far away in third world countries. However, for most of history malaria has been incredibly widespread and in the case of Europe, present in marshlands from Hungary to London.
One city of note that particularly suffered with malaria is Rome; from the Antiquity to the 20th century, malaria was a scourge on the city and its marshy surrounding "Campagna". Even in the 1920s, the Italian Red Cross reported that 80% of those who spent a single night in the Pontine Marshes near Rome became infected with malaria, and this was after centuries of gradual land reclamation and drainage efforts to reduce the marshes. Malaria was so prevalent in ancient Rome, that some historians posit that it was a factor in Hannibal and Attila the Hun's decisions to bypass Rome. Some also propose that increasingly severe malaria epidemics could be a reason behind the decline of Western Roman Empire.
The reason for bringing up Rome is mostly due to the theory that Roman doctors came up with during their close interaction with malaria. The basic relationship between malaria and swamps was well known before the Romans, but according to prevailing Greco-Roman medical beliefs, the source of malaria had to be from "bad air". As a result, Roman doctors came to the conclusion that swamp air itself was unhealthy and pestilent, a view point that the rest of the western world followed until the late 19th century. This influence is visible in the very name malaria, which literally means "bad air" in Italian. The belief that simply breathing bad air from swamps could result in contracting a deadly disease with no real cure is a tremendous motivator to avoid them. The negative portrayal of swamps in many horror films and cartoons, with thick clouds of swamp gas, is probably a reflection of this old belief.
Extra: Not everyone believed malaria was bad swamp air. Some ancient Romans correctly theorized it was the biting swamp insects. Their theories just never became main stream until it was scientifically proven multiple times in the 19th century.
Sources/further reading on the percieved association between swamps and disease historically:
NELSON, MEGAN KATE. “The Landscape of Disease: Swamps and Medical Discourse in the American Southeast, 1800-1880.” The Mississippi Quarterly, vol. 55, no. 4, 2002, pp. 535–67. JSTOR, http://www.jstor.org/stable/26476658.
SNOWDEN, FRANK M (2006). The Conquest of Malaria: Italy, 1900-1962. New Haven: Yale University Press
HEMPELMANN, ERNEST, and KRAFTS, KRISTIN. “Bad Air, Amulets and Mosquitoes: 2,000 Years of Changing Perspectives on Malaria.” Malaria Journal, vol. 12, no. 1, 2013, https://malariajournal.biomedcentral.com/track/pdf/10.1186/1475-2875-12-232.pdf
PAPPAS, GEORGIOS, et al. “Insights into Infectious Disease in the Era of Hippocrates.” International Journal of Infectious Diseases, vol. 12, no. 4, 2008, https://doi.org/10.1016/j.ijid.2007.11.003.
There is almost certainly no single origin for the trope of the grim, mysterious, or downright evil wetland. It appears in cultures across the globe, in early texts as well as more recent media. Wetlands cover about a quarter of the Earth’s land area, and there are many, many types—peat bogs, salt marshes, mangrove swamps, floodplains… Given this impossible-to-cover scope, I’m going to point to just a few factors that may play into the negative perception of such biomes, at least for some cultures, at least some of the time. Also I’m interpreting the “evil and foreboding” of your question pretty widely, to encompass a spectrum of weird, supernatural, and frightening associations.
I’ll cover five broad categories of spookiness associated with wetlands: disease, predators, natural dangers, the concept of the liminal, and lawlessness. This isn’t meant to be comprehensive, and there's undoubtedly more to be said. Also, as you’ll see, aspects of each of these qualities inform and shade into one another.
/u/lunes8 goes into this in more detail, so just briefly: the association between wetlands and disease isn’t some relic of ancient superstition. Mosquitoes still kill about 700,000 people a year, far more than any other type of animal. As this map shows, more than half of the world’s land was malarial prior to the twentieth century, and this half included nearly all regions that were historically densely populated. Cholera, typhoid, and other nasty diseases are likewise linked to water supply, and so to the landscapes from which people draw their water. In premodern Eurasia, the killing power of wetlands was associated with the “miasma,” the fetid vapors of decay that rise from swamps. The ancient Greeks and Chinese alike attributed numerous fatal diseases to this fog, and the belief that miasma causes epidemics was prevalent into the 19th century before finally being replaced by germ theory.
Moving on to somewhat larger animals, wetlands are home to a number of dangerous beasts, including crocodilians, snakes, sharks and other predatory fish. The Sundarbans, the world’s largest mangrove forest on the Bay of Bengal, contains a famously deadly population of tigers. Bears, boars, hippos, and other irascible megafauna also frequent these habitats, particularly at times of year when humans may also be more likely to enter them in search of resources like salmon or mast. Alongside—and perhaps at least somewhat inspired by—these biological creatures are the countless monsters said to dwell in swamps, marshes, lakes, and rivers: the Stymphalian birds and Hydra of Greek myth, the Australian bunyip, the mishipeshu or “underwater panther” of indigenous North/Northeastern America, the nahang of the Iranian world (whose name means something like “the one who pulls its prey beneath the surface”), and the Swamp Apes and Loch Ness Monsters of modern cryptozoology, to cite just a few. Some scary water dwellers, like Peg Powler of the Tees, may play “nursery bogey” roles, keeping children cautious around dangerous activities (like straying too close to deep water.) Others, like Grendel, are used to express complex anxieties about culture, history, and colonization. But in various forms, their stories are told worldwide, rooting a deep connection between wetlands and uncanny, often malevolent beings.
Probably equally important for the imagining of these monsters are the numerous natural dangers of wetland environments. Quicksand is probably the most cinematic. Drowning remains the leading non-congenital cause of death for children 1-4, and traditional balladry is full of woeful tales of drowned lovers. Simply getting lost in the wilds is incredibly dangerous, and shifting ground, mist, lack of landmarks, and thick vegetation can all make wetlands especially easy (and treacherous) places to get lost. The power of swamps to bewilder travelers is typified by will-o’-the-wisps, glowing atmospheric phenomena (probably including flares of marsh gas as well as bioluminescent animals and plants) imagined as wicked spirits leading the unwary into the mire.
The presence of supernatural beings is in turn linked to the perception of wetlands as liminal or transitional zones. They often occur at the junctures between different biomes, and around bodies of water which have often functioned as boundary markers for human societies. Wetland topography is regularly re-shaped by flooding and other forces, and constant transformation is also perceptible in the amphibious creatures that live in these areas. These and other associations have given an explicitly otherworldly cast to wetlands in numerous cultures. Many peoples associated with the Southeastern Ceremonial Complex along and east of the Mississippi River identify the wet, gloomy, and transformational aspects of swamps with the Lower World, a realm of chaos and death as well as wealth and fecundity. In Northwestern Europe, lakes and bogs are frequently depicted as passage points between the human world and otherworldly realms. Medieval texts like Branwen ferch Llŷr and Tydorel describe the terrifying consequences of human interactions with the denizens of these underwater spaces. As with the Southeastern Ceremonial Complex, there was a recognition that wetlands contained great wealth for those who dared to delve into them—but that these rewards were often guarded by uncanny powers. There really was literal treasure in European wetlands—many Bronze and Iron Age goods have been recovered from ritual deposit sites in pools, swamps, and marshes. The occasional association of such items with bog bodies, corpses eerily mummified in peat bogs, may have further contributed to the perception of wetlands as sites inhabited by bizarre and unsettling entities.
And of course, as /u/ThatHapsburgMapGuy says, wetlands have always been inhabited by human societies. While I disagree with their contention that the vilification of wetlands “must be recognized as a discourse of modernity”--there are few more evil swamps in literature than Grendel and his mother’s lair in Beowulf—I fully agree that it is, also and often, “a discourse of exclusion.” Following their citation of James Scott, it’s reasonable to say that wetlands are up there with mountains and deserts as biomes that have historically resisted systems of state control and legibility. Border zones, difficult to map, dangerous to outsiders for all the reasons discussed above, very hard to pacify with roads and fortresses—wetlands have long attracted those who seek to live outside (or on the margins of) states. People move to, or stay in, these zones for a variety of reasons: for example, holy solitude (like Saint Guthlac), banditry (as depicted in the great Chinese novel Shuihu zhuan, ‘Water Margin’ or ‘Outlaws of the Marsh’), freedom from taxation and conscription (as with the runaway serfs who contributed to the formation of Cossack communities along the Dnieper), or anticolonial resistance (the last native Prince of Wales, Dafydd ap Gruffydd, and the Wampanoag sachem Metacomet are only two of the many resistance leaders who made their last stands in swamps). From the perspective of central governments, these regions and their intractable communities are easy to depict as enemies of civilization, even as states covet the resources they hold.
All of these features feed into the fictional “bad reputation” of wetlands. Note, though, that especially the last two factors can have a positive valence, depending on narratorial perspective. For every foreboding swamp, there is an idyllic riverbank, Yoda’s hut, or rebel stronghold. These contest the discourse of wetlands as obstacles to human flourishing, and insist instead on their ecological, social, and political importance.
This is a much bigger question than meets the eye.
The first point to note is that swamps and wetlands were vastly more common prior to the seventeenth century, and were always home to human communities for exactly the reasons you mentioned. Whether in waterlogged mountain valleys or in the vast marshes which stretched alongside the always-shifting rivers, people lived alongside and in wetlands for almost all of human history. James Scott has recently argued (somewhat provocatively) that wetlands were the real cradle of civilization, hosting settled communities many centuries before the first city-states coalesced [Scott, 2017]. And more specifically for Northern and Central Europe in Early-Modernity, the cold and wet climatic patterns of the Little Ice Age probably meant that living with water was a normal aspect of human life for the majority.
And while disease has already been noted here, wetlands could provide essential resources for survival. For example, when the uplands dried out in the early spring and late summer, livestock could reliably be put to pasture in wetlands and served as keystone species [Biro et al. 2019]. When agriculture failed due to disease, climate, or war, the wetland offered a reliably extreme diversity of food sources, not to mention refuge from landlords, tax collectors, and pillagers. Certainly African slaves and Native Americans found the dense wetlands of colonial America places of refuge and security, where they founded maroon communities. Perhaps as late as the 1850s in Hungary (the Pákász), 1991 in Iraq (the Marsh Arabs), and even today in the Danube Delta in Romania (the Lipoveni) communities continued to live in wetlands on mixed cultivation and hunter-gathering, sometimes using reeds to build their homes.
So the question of how swamps and wetlands became places of evil must be recognized as a discourse of modernity, and as a discourse of exclusion. When early modern European writers talk about the people who live in swamps, they invariably emphasize their backwardness, sickliness, and lack of industry. Malaria is a very good reason to not want to live in an early-Modern wetland, but this discourse is one specifically used to justify the drainage of wetland for intensive agriculture first by the aristocracy, and then later (in the mid to late eighteenth century) by the Absolutist state. As David Blackbourn observes, "violence was the midwife of reclamation." Attempts to drain wetlands invariably met with local opposition, like the famous "Fen Tigers" who sabotaged the draining of seventeenth-century England. For this reason, land clearance became a military affair, and one of the key reasons for the founding of military engineering corps in the Habsburg Empire, Prussia, and to a lesser degree France and England. Even today, it's the US Army Corps of Engineers which is responsible for building and maintaining the massive dikes desperately trying to keep control over the Mississippi River. At the same time, the people who lived in and relied upon wetlands were always intentionally made invisible.
Back to your original question. I would say that while wetlands have always been avoided for their diseases by some, the negative idea of swamps as evil and foreboding was radically intensified in the nineteenth century, in narratives written about the landscape that existed before mass drainage works. Where the Hungarian bishop Nicolaus Olahus describes the marshes of the Banat region in the sixteenth-century as extremely rich in fish products, 300 years later the Hungarian revolutionary nobleman Mór Jókai describes the same region as being (in the previous century) a "waste and roadless empire of marshes; a country of wolves, of frogs and turtles... covered both for people and beasts by a poising mist" [Magina, 2015]. He gets even weirder, claiming that there were clouds of mosquitoes and gadflies so thick that they could kill cows, and so many "serpents and other reptiles’ armies" that outside in the fields their heads rose like never yet seen plants." Thing is, Olahus described a landscape he could see around him, while Jókai was describing a world that was already long gone.
For reference, I'm hoping to start a project mapping biomass loss between the 1780s and 1820s in the Habsburg Empire using the first topographic maps. My back-of-the-napkin estimate is something like an 85% reduction in the wetland of the Tisza [Theiß] river in southern Hungary due to canalization, way before environmental and climate data even began to be recorded.
James C. Scott, Against the Grain: A Deep History of the Earliest States, 2017.
David Blackbourn, The Conquest of Nature: Water, Landscape, and the Making of Modern Germany, 2007.
András Vadas, Weather anomalies and climatic change in late medieval Hungary: Identifying environmental impact, M.A thesis (Budapest: CEU, 2010).
Adrian Magina, From Swamp to Blessed Land: Transforming Medieval Landscape in the Banat, 2015.
Timothy G. Anderson, Cameralism and the production of space in the eighteenth-century Romanian Banat: the grid villages of the ‘Danube Swabians’, 2020.
Biro et al., Reviewing historical traditional knowledge for innovative conservation management: A re-evaluation of wetland grazing, 2019. https://www.researchgate.net/publication/341440968_Conservation_and_herding_co-benefit_from_traditional_extensive_wetland_grazing