They don't go bankrupt in the conventional sense. When they go bankrupt economists like to use the term "Hyper Inflation". This means that the currency they produce becomes worthless.
Maybe you can explain it to me like I'm five. I've been occasionally watching the Turkish Lira this past year. The rates against the USD are still sinking. Against the EUR it's pretty stable. Yet allegedly they have something like 80-150% inflation in Turkey, while the EUR-zone has 10%. How does this work, why isn't the Lira becoming "worthless" with that amount of inflation?
When governments produce a lot of money, their dollar becomes substantially less. This causes them to need to produce even more money (because money which used to be enough is no longer), creating a cycle and a desperate attempt to produce something out of nothing, where eventually what used to cost one dollar literally costs trillions of dollars - hyperinflation.
Banks manage a lot of money, so if they go bankrupt the government needs to bail them out by printing a lot of money, causing massive inflation. And if the government needs to pay off foreign creditors (they do), and tries to address the resulting poverty caused by the inflation, it leads to printing more money and hyperinflation.
EDIT: Relating to the Turkish Lira and why that isn’t hyperinflating: I don’t know where exactly the line is where “high inflation” triggers the cycle and becomes hyperinflation. I suppose they still have resources, so their currency still has some worth. Just, either they don’t have as many resources as before, or the government is printing money which it spends on itself in order to drain money from the average person without explicit taxation.