Lawyers exist for a reason. They know the law, and they know how to do things you don’t. They can get you out of jail in some cases.
For instance, a lawyer could attend hearings on your behalf and argue that you deserve to be released from jail pending a trial. They can show the court you’re not a flight risk. They can show the court that you’ve never committed a crime before. They can articulate legal arguments that you simply don’t have the training to put together.
Your lawyer could possibly help you avoid jail entirely in some situations. For instance, they could help you clear a warrant without going to jail. They can help you get a case dismissed, which means you never have to face any punishment for the charges filed against you.
Obviously, every situation is unique, and no one can guarantee that you won’t go to jail. But, you have a much better chance of avoiding or reducing jail time when you have a lawyer on your side.