Any urban environment in William Gibson's novels counts as this, but particularly the settlements that each of his cyberpunk trilogies are named after: the Sprawl — a continent spanning enclosed megacity; and the Bridge, a lawless community built on the carcass of a crumbling Golden Gate Bridge. Idoru's 'Walled City', an online community comprised almost entirely of hackers and (modeled after the real life wretched hive, the Kowloon Walled City) might also count, despite being virtual.
The Dipple—a refugee camp featured in several novels, such as Catseye and Judgment on Janus. Its ugliness is thrown into sharp relief by the fact that it is located in Tikil, the only city on the pleasure planet of Korwar.
In her novel Operation Time Search the city of Atlantis is described like this. It's a Not-So-Safe Harbor ruled by evil demon worshipping priests, and The Hero goes to a Bad-Guy Bar for information.
In The Angaran Chronicles the underground city of Valtagan and capital of Hamar in the novella Hamar Noir is this. The main character Anargrin being accosted by criminals quite quickly as he investigates the streets.
Aurora Cycle: Sempiternity, the World Ship, is a Space Station frequented by pirates and run by a ruthless crime lord, with seedy locations aplenty.
Bas-Lag Cycle: New Crobuzon from China Miéville's Perdido Street Stationandsequels blows most examples here out of the water in terms of sheer ugliness, mostly because of its corrupt, despotic government. Its ostensibly democratic parliamentary system is truthfully an oligarchy of wealthy capitalists who ignore crime against ordinary citizens, but send death squads to deal with dissenters, essentially ensuring that the city stays a brutal lawless mess forever. Other criminals are punished with Body Horror and a life sentence of slavery. Poverty is endemic and racism is rampant. Really, all you need to know about the ruling class there is that a serial killer infamous for plucking out his victims' eyes turned out to be the mayor, ordering the deaths of random people because he had a condition that required his eyeballs to be regularly replaced.
Conan the Barbarian: The pirate town of Tortage in the Barachan Islands. And throughout almost all Conan media, Shadizar, otherwise known as Shadizar the Wicked, capital of Zamora, Crossroads of the World.
Discworld: Ankh-Morpork in the earlier books; The Shades turn this all the way past 11 up to 125, to the point where "a ghastly frieze of tortured silhouettes" on a wall is deemed less likely to attract attention than "fresh paint". And informing three very drunk Watchmen that they'd blundered into the Shades was enough to sober them instantly.
Havelock Vetinari seriously cleaned up the city, though, by legalizing the Thieves' Guild and putting them in charge of regulating the muggings. And the Watch became very efficient later under the influence of Captain Carrot and Samuel Vimes. To the point Ankh-Morpork is in the later books a bustling center of economic activity where, according to Going Postal, "being attacked while going about your lawful business in Ankh-Morpork was now merely a possibility instead of, as it once was, a matter of course." You can still get killed at night just by wandering in the wrong places, but the pragmatic Ankh-Morporkians consider this "suicide". And a sure sign of being either a tourist (and thus accidental) or Too Dumb to Live since if you're a local you ought to know better.
Subverted in Feet of Clay, which has a bar named "Biers", a bar for supernatural creatures which contains at least a dozen deadly creatures every evening, but which is perfectly safe for a blind old widow named Mrs. Gammage to visit every evening. The creatures even go so far as to act like bar regulars she remembers from before the bar became "Biers", and protect her when she is not in the bar. Don't ask what happened to those poor idiots who robbed her aka committed suicide. It's best we don't ever find any details out. She did get her stuff back, however. And... an apology note.
The Divine Comedy: The lower circles of Hell gradually become less individual and more of a connected society of back-stabbing, lying, and eternally self-destructive shadows of what were men.
The corrupt politicians send secret signals to tell the others that the demons hunting them are elsewhere, a fact we only learn because one of the politicians offers this information to the demons in exchange for safety.
The thieves know each other names, form in groups, and refer to each other as comrades, until one of gets turned into a snake. At that point, the still-sentient thief will seek out their friends and attack them, returning to their normal form while reducing their supposed comrade to a snake. The cycle repeats forever.
Dante can't even talk to the inhabitants of the tenth bolgia, designated for pure falsifiers, because they're too busy running from, fighting with, or screaming at each other. The poem's Mentor Archetype has to order Dante to leave, lest the infernal society take some hold in his mind.
The core of Hell is occupied by Satan, whose giant mouths make him most qualified to communicate. But by his sin, his faculty to communicate has been turned only to destroy others, and so Satan's mouths serve as meatgrinders reducing Judas and two other traitors to blood.
The eponymous Domina City of the web-novel Domina. Genetically engineered monsters roam the streets, gangs use Bio-Augmentation to turn into vampires or demons, and if you can't get in contact with someone, it's safe to assume they're dead.
Old Undertown from The Edge Chronicles: polluted, impoverished, crime-ridden, full of thugs and cutthroats, and generally unpleasant. However, its also the beating heart of society on the Edge, and is at no point portrayed as completely inhospitable or beyond hope. Until the Rook Trilogy that is, when nearly half of it is destroyed and the rest becomes nearly dystopian. It eventually gets destroyed, which is probably a good thing.
Michael Moorcock's The Elric Saga: Elric's first adventure involved his tracking down his evil cousin Yyrkoon to the "mean nations" of Oin and Yu. Their shared capital city Dhoz-Kam is seedy, filled with corrupt, dirty, disease-ridden lazy people. Their navy consists of a dozen or so filthy, unseaworthy fishing boats. And Elric was once compelled to visit a city called Nadsokor, also known as the "City of Beggars". This city's population consists entirely of those who are physically, mentally, and morally deformed.
Esther Diamond: Altuna, Pennsylvania has a reputation as this among the magical community. The first book makes a Running Gag out of of the incredulous reaction of any Muggles informed of this.
John C. Wright's The Golden Oecumene: In The Phoenix Exultant, Talaimannr is the truly wretched home of everyone whose uncivilized habits make them unfit for society.
The Han Solo Trilogy: Par for the course in Star Wars. The one we see the most is Nar Shaddaa, the "smugglers' moon" orbiting the homeworld of the Hutts, where Han and most of the other smugglers employed by them make their home. Zigzagged as although there's only one government official on-planet (he does basically nothing) most of its inhabitants are criminals and the lawless areas definitely do exist, there's also plenty of people who live or work on the planet fairly comfortably. It likely helps that the crime is mostly organized, and they wouldn't tolerate too many street crimes cutting into their profits.
Ysai, the capital city of the planet Gammu from Heretics of Dune definitely counts. Miles Teg notes the development of the city was purposefully directed into something "worse than ugly", and Reverend Mother Lucilla is eventually driven to tears after seeing the corrupt, desperate and dangerously violent state of the city's inhabitants firsthand. Think about that for a moment. The city was so bad it made a Reverend Mother cry.
"The Horror at Red Hook" by H. P. Lovecraft is largely a long rant about how horrible the eponymous part of New York is, with all its degraded foreigners and illegal immigrants. Of course they also have a human-sacrificing cult, and the climax involves a vision of a Fantasy Kitchen Sink of all possible hellish horrors underground under Red Hook that puts Fantasia's "Night on Bald Mountain" to shame.
The city of Godwin in the Hostile Takeover (Swann) series is run by a mixture of armed gangs and literally feuding corporations. There is no law enforcement beyond what someone's willing to pay for.
John Carter of Mars: If you ever end up on Barsoom, avoid the old cities like Torqas and Warhoon (especially Warhoon). They tend to be crawling with either Green Martians, white apes, or both. Phundahl and Toonol are also pretty horrible; the former is filled with religious fanatics, while the latter is populated by the closest Martian equivalent to Objectivists.
In Angélica Gorodischer's Kalpa Imperial, Mesziasdar sees the Font of Five Rivers, an artistic but somehow libertine city, as a wretched hive, so he seizes it and transforms it in a military garrison.
Mark Delewen and the Space Pirates has Mark qouting 'A wretched hive of scum and villainy' as he enters the Ondoog system; due to it housing a spaceyard that catered to criminals.
The entire Roman Empire (with special mention given to the cities of Rome and Ephesus) is portrayed as this in The Mark of the Lion trilogysexual deviance and debauchery are the norm for all social classes, especially the aristocracy, infidelity, domestic abuse, and divorce are unremarkable, religious intolerance is rampant, murder is easily hushed up, and then theres the Gladiator Games and the fact that the vast majority of citizens are totally accustomed to the violence, sometimes even bored by it.
With the story largely focusing on the city's underground, poor, and criminal elements, Paris in Les Misérables gives off this feel.
This is at least how Winston and the party members view the Proles, due to party propaganda and the standard class warfare. To the Proles themselves, it's just your standard poor/working-class lifestyle, to the point that an older who remembers life before IngSoc considers there to be no real difference from his life before the revolution, save for the absence of a few novelties like top hats and coat-tails. And the Proles themselves are the lucky ones; Big Brother doesn't care so much if he doesn't consider you important.
King's Landing, the capital of the Seven Kingdoms in A Song of Ice and Fire is a vice layer cake of a city. Parts of it are pretty on the surface and even escape the smell thanks to careful landscaping, but it is still a very dangerous and nasty business trying to navigate those corrupt political waters. Other layers are fairly typical for what is the largest city in a country not known for stirling community services or civic pride in general; not safe and quite corrupt, but not unusually so — but, hey, it boasts sewerage systems (that feed into the bay and still stink to high heaven)! Other districts, like Flea Bottom or the newer parts outside the city walls, live much closer to truth in advertising by wearing their incredibly ad hoc, lawless, dangerous and squalid natures quite openly, thank you very much.
Lordsport in the Iron Isles has an unsavoury reputation with rumours of foul deeds and vile undertakings. The thing is, it's likely to be subverted a little in this case. It is still a waterside port in the Iron Isles, so, yes, it's very highly unlikely to be included in the top ten Westerosi safe places to get black-out drunk in if you want to wake up alive. But, what the Ironborn consider truly "vile, underhanded, sinful, godless and lewd" other people would call "upfront trading enterprise using contract law rather than blatant piracy to take you to the cleaners with". Yup: different strokes.
There's also Asshai-By-The-Shadow, a port city at the edge of the known world where nothing ever grows, the water is toxic, and everything is dark, even during the day. Since no crops grow there and no animals can long survive, anyone actually living there is heavily reliant upon food and drink shipped in from foreign lands, and the place is crawling with every kind of magic-user imaginable — mostly of the kinds normal people don't want to imagine in the wee small hours. Most of them, presumably, are like Melisandre: The Needless or at least close enough to it, which might help explain why anybody can be found there at all. Whatever you do, don't go out at night. Nobody knows for sure what happens and the rumours mushroom with each and every foreign sailor and/or idiot who vanishes, but they won't ever be seen again.
Star Wars Legends: The X-Wing Series has Gavin Darklighter from Tatooine going to the underlevels of Coruscant and thinking that "if Mos Eisely was considered the armpit of the galaxy, this part of Coruscant could be considered anatomically lower and decidedly less hygienic." A few chapters on, Corran Horn, wandering around and not paying attention to his surroundings like an idiot, finds himself at a very low-level bar. He was a cop, and thinks to himself that his beat on Coronet City had seedy spots, but they appeared positively immaculate and safe compared to here. He'd chased fleeing Selonians through sewers with better atmosphere and more consistent lighting than this bar, the Headquarters.
Sanctuary, the setting of Robert Asprin's Thieves' World series, embodies this trope. The city of Sanctuary itself is a Wretched Hive (although sufficient wealth or power can get you a modicum of safety and luxury), while the area called The Maze is The City Narrows and the tavern called The Vulgar Unicorn is the Bad-Guy Bar.
Lampshaded in C.R. Jahn's Underground. The Twisted Spokes is an "Ultimate Biker Bar" which sells hard drugs and permits duels on premises.
The Venus Prime series has Labyrinth City on Mars and Shoreless Ocean on Ganymede. The former is a corrupt frontier town being used as a battleground in a war between labor unions, while the latter is a hotbed of racism.
In Dan Abnett's Gaunt's Ghosts novel The Armour of Contempt, the swelter decks. One gambling den there sets out to beat Merrt to death, and when Ludd interrupts, intends to kill him as well. Hark was there to back Ludd up, but as he was in the swelter decks, some soldiers thought they could Revenge their captain on Hark safely; fortunately for Ludd, he dealt with them quickly enough.
In William King's Space Wolf novel Wolfblade, the underhive that they raid because of the Cult. There are dispossessed people down here, and a Brother Malburius, ministering and acting as The Medic, but also plentiful horrors.
The Witchlands has the Red Sails part of the Saldonica city-state. It's a maze of run-down alleys no-one has swept in a thousand years, filled with pirates, runaways and criminals all to happy to kill you for your earrings or capture you and sell you into slavery.
Before Xandri Corelel was recruited by the Carpathia, she lived in a miserable, crime-ridden slum where she was at a daily risk of being stabbed to death by her drunken neighbor or recruited by the local brothel.
Dead Donkey, Nevada, from You Are Dead (Sign Here Please). The main municipal pastimes are arson and Muleball, a sport have nothing to do with mules or balls but that consists of people beating each other up on the street and stealing each other's valuables. The main income is from tourism, which is to say, the city offers free trips there for the gullible and then charges them outrageous fees for the trip back home.