Those who can’t afford bail or a lawyer other than a public defender have two choices. Sit in jail for who knows how long until trial or take a plea deal and have an idea when you can get out.
This is definitely part of it, but the other is that prosecutors in many jurisdictions can actually apply pressure during these discussions, including threatening to seek harsher sentencing. This kind of coercion should, of course, be straight up illegal, but it is not.
Another factor is that many prosecutors are elected. And till recently, at least, appearing "tough on crime" by claiming stats about "putting away x number of criminals" worked very well. So you have the prosecution incentivized to seek convictions, rather than justice. And that has had network effects on the judiciary and the police, as well.
There's a recent wave of progressive prosecutors being elected in big cities on an explicitly justice based message, but they've encountered strong push back from the police.
This country is a long way from an equitable justice system. The focus right now is on how it harms minorities, which is appropriate since the brunt is borne by them, but cleaning up the justice system is to everyone's benefit.