I think there could be several good reasons for plea bargaining. I'm not a lawyer, so I could be off on some of the finer legal issues, but the bargain is usually made between the prosecutor and the defense. It could be that, for some reason, they have enough evidence to convict on the lesser crime, but taking the larger crime in front of a jury might be risky. For both sides. Or perhaps the criminal is willing to testify to an even greater crime committed by someone else, and the prosecutor feels it's more important to, for example, get a murderer off the street than a thief.
The reason for going to court is because the prosecutor cannot issue a sentence. Only the judge can do that. And he may be restricted, by statute or precedent, on how great a sentence he can give. And if the prosecutor claims that the defendant is cooperating in a capital case, the judge might take that into account. It's a complicated process, to be sure.
Another possible reason for plea bargaining is expense. Trials cost a lot of money, paid by taxpayers. If you can accept a guilty plea for a relatively small crime imposing, say, a three year sentence, why go to the cost of a trial for a somewhat bigger crime which may only incur a four or five year sentence?
Part of the problem, as I understand it, is that the system is overloaded, with too many criminals and not enough prosecutors and judges. And part of the reason for that is the criminalization of relatively harmless activities, such as marijuana possession. Plea bargaining is one way of easing that overloading.