Tropes such as this and Cowboy Cop tend to be more beloved in fiction than in real life for one important yet often overlooked reason: fiction tends to explain things to the audience. Things like "this is the person who did it". If the audience is outright told who committed a crime, then the perception is that any lawyer defending that person is obstructing justice, and any prosecutor going after someone else is miscarrying it. And in most places, someone arrested in the middle of committing a crime gets much the same civil rights as someone arrested after the fact; they're entitled to legal representation, entitled not to say anything until they've consulted with a lawyer, entitled to a fair and impartial trial by a jury of their peers, and so forth. All that would really be different would be that if the case did go to trial, the charges might be slightly different depending on precisely when they were nabbed (attempted murder, say, instead of actual murder) and the prosecution's job would presumably be made much easier by the fact that they had plenty of witnesses, including police officers, who they could call to testify against the defendant, and evidence that could be more easily preserved. It would be a much more open-and-shut case — which is probably why it doesn't appear much in fiction, because there's less drama (less ambiguity about who the culprit is, and said culprit is more likely to cut a deal rather than risk a trial which they'd be more likely to be found guilty at, and so forth).
To say nothing of the fact that in most cases, when criminals are caught in the act of committing a crime, they generally plead guilty (often on the advice of their own attorney) and the trial never takes place at all. Obviously, this doesn't make for good TV, which is why you almost never see it on police procedurals.
In defense of this trope, it has to be noted that in almost all cases, it's the private attorneys who are seen as unprincipled and corrupt, not public defenders. There's good reason for this belief;
Private practice has access to professional consultants who are permitted to screen jurors - supposedly for impartiality - but in effect picking them for their likelihood to find their client innocent. Public defenders can't afford those.
There are five times as many private attorneys as there are public defenders.
Despite this, private practice pays on average twice what public defense does - there are your basic "one-dollar-plus-percentage-of-settlement" ambulance chasers, and there are ones that make thousands per hour.
Private practice spends weeks on each case, meets with clients repeatedly - often they're on a first-name basis with them - and sometimes entire teams of attorneys defend a high-paying client. Public defenders have case loads so high that on average, they can spend only 12 minutes on each client. Not just in court, but also meeting them to discuss their case. Public defenders often see their clients only twice - when they are arrested, and when they go to trial, both for less time than most spend in the bathroom every morning.
So to sum up, the Amoral Attorney manipulates the system on behalf of his clients, gets rich doing so, works a lot less hard, and spends significant amounts of time finding ways to keep his clients from being punished. And only rich people can afford them - usually someone they consider a close personal friend who helps him get away with crimes. On the other hand, poor and middle-class people have to make do with a stranger who was ridden hard and put away wet on his way to his next case. It shouldn't be any wonder that most consider high-paid attorneys to be monsters who take pride and pleasure in making the world suffer.