I don't have enough points to comment on Phillip's answer, but it appears wrong for the USA. First, declaring personal bankruptcy is not a lawsuit. Second, personal bankruptcy does not usually qualify for legal aid.
Did you not Google your question? I see good answers on Quora and Reddit. I am answering this question for merely personal bankrupts who are almost penniless.
One straight forward answer is that a penniless bankrupt may need to sell his "vehicles, houses or other goods and property".
Obviously a person requiring bankruptcy doesn't have a bunch of cash. But they can probably cobble together $200-300 for that flat fee. The game for the lawyer is volume. They collect the flat fee from lots of different folks. Much of the work is template-driven. Meaning, they're don't usually have to create a lot of original work, which allows him to accept more clients.
Most states have a law either (1) making sure legal fees can’t be gotten rid of in bankruptcy; or (2) making sure your lawyer gets paid before most other creditors.
I quote https://www.thebankruptcysite.org/resources/bankruptcy/bankruptcy-lawyers/how-do-bankruptcy-lawyers-g.
If you're wondering whether you can charge the fees, the answer is no—you can't use your credit card shortly before bankruptcy to pay your lawyer. But a friend or family member can do just that—and many do.
It's common for a filer to reach out to family and friends for help after meeting with a bankruptcy lawyer—especially when realizing that financial relief is in sight. And those close to the filer often recognize that wiping out debts in bankruptcy is more cost-effective than continuing to help the filer get by each month.
But when that's not possible, most filers stop paying bills that will be "discharged" or wiped out in the bankruptcy case, such as credit card balances, medical bills, payday loans, and more, and use the funds toward bankruptcy fees instead. Bankruptcy courts accept this practice, but you'll want to ensure that you are qualified to file for bankruptcy before you stop paying bills. Otherwise, you might find yourself in a worse place financially.
. . .
Most lawyers will let you pay your attorneys' fees in installments if you need time to come up with the entire retainer. But as discussed, the lawyer won't file the case until you've paid the total amount due. It's not uncommon for people to hold onto their funds until they have the entire amount once they learn that paying in installments won't speed up the Chapter 7 filing process.
. . .
Some bankruptcy lawyers will accept as little as $100 to file your case plus the court filing fee. But they're doing the work assuming that you'll stay in the plan. If you can't pay your monthly Chapter 13 payment and the court dismisses your case, the lawyer won't receive full payment. You can learn about calculating a Chapter 13 plan payment here.
Because of the risk involved, many lawyers will want the same amount they would receive for a Chapter 7 case before filing and will let you pay the remaining amount—probably another $1,500—through the Chapter 13 plan. In riskier cases, the lawyer might ask for more.