The first point to make is that "big, long dresses that trailed on the ground" are not exactly common all throughout the past - they were fashionable during specific periods. For instance, the mantuas of the 1680s through 1700s often were made with long trains which might drag on the ground; in the 1780s it again became fashionable to have a slight train (in both periods, the visible petticoat worn under the gown would be cut to a "round" length and not touch the ground). Skirts in the 1840s through 1860s could be worn at about floor-length, and in the 1870s and 1880s a long train was again fashionable. However, between these eras it was generally fashionable for the skirt/gown to be made on the shorter side, leaving the feet clear.
The second point is that not every woman was dressing like this. "Fashionable" is a key word: it relates to social class, purpose, and intention. In general, the kind of woman who was going to wear a train as a matter of course would not be walking through muddy paths filled with manure - she was going to stay indoors, pop into a carriage just outside the front door, or stroll along a patio or tidy garden. A farmer wouldn't wear a train, a servant wouldn't wear a train, a traveler going far on foot wouldn't wear a train, because you're right, it would be very problematic.
We're drastically cutting down the incidences that you're asking about to a small proportion of women and only a bit of the time. So, what did people do when they did find themselves in this situation?
One thing was simply to hold up or pin up the train. A number of ca. 1800 fashion plates show women draping the trains of their white muslin gowns over one arm or reaching behind to pull it up, as they would not last very long on the dirty ground; in general we can assume this was a fairly common "quick fix" when necessary. They weren't stupid. Given the choice between trailing your dress in the mud and having to hold up the hem, women would generally choose the latter.
On trained gowns of the 1870s and 1880s, we often see an extra piece added to the bottom of the skirt, a pleated ruffle of cotton organdy called a balayeuse ("sweeper"). These could be purchased ready-made and stitched in when needed, then taken out when too dirty and replaced, although I think they were typically meant for indoors dirt and dust rather than actual filth. Such skirts also sometimes had a cotton velvet or wool ribbon facing on the hem to take the wear of brushing over the ground.
Now, as to carrying disease into the home - I think it's unlikely that this was a real problem given how diseases generally spread, but in the late nineteenth and early twentieth centuries there was indeed a concern that women were bringing typhoid and other infectious diseases that terrified city-dwellers into their homes and infecting their families. Now, on the one hand this reflects the general focus on sanitary conditions that went along with this time period - brass bedsteads, white tile floors and walls, germ theory, etc. On the other, it reflects social anxieties of the day. Do women put following fashion ahead of their health and the health of others? Should women focus their attentions on domestic matters and avoid going out into the world? Are cities being polluted with disease because of immigrants? And so on. It's not a simple question and I don't believe there's a solid answer.
What about pattens? Raised shoes.
Were they a thing or is it like iron maidens, retrofitted?