The more I read about European history in the Middle Ages and the early modern period, the more common it feels like it is to read something along the lines of, "...and by that point, the Spanish/French/Habsburg crown was in hundreds of thousands of florins worth of debt to prominent bankers, which they had no realistic hope of repaying any time soon."
How did bankers cope with this kind of behavior? In modern society we have all these apparent safeguards to protect the stability of our complex banking systems. But these bankers seem to have been stiffed by their customers on a regular basis. Were banks just constantly folding a lot of the time? Why would anyone get into so risky a business in the first place?
This may be a bit early for you but I wrote an earlier post on Italian banking in Medieval England under the reign of Henry III and Edward I, in which one could see one of the first cases of a European monarchy making extensive use of a single banking family for most of their loans. For further reading, I recommend R. Kaeuper's Bankers to the Crown: The Riccardi of Lucca and Edward I, it's a bit old, but there aren't too many books on the topic.
The post focuses mostly on your last question on why one would want to loan out so much money in a such a risky enterprise. In the case of Late 13th-Early 14th century England (This is the era I wrote the post on, but this economic policy lasted all the way to the 16th century), you're assumption is right. This was a highly fragile business relationship between the bank and the crown wherein the kings were often dismissing and bringing in new banking companies (Almost exclusively Italian) to supply their loans.
However dangerous this was, the main reason that companies kept providing loans to the English crown was that the benefits were just that much enticing. Again, I'll write on the family that I previously described, being the Riccardi of Lucca (Active from the mid to late 13th century under Edward I) as they were the first to become involved in this new model. In short, the Riccardi would provide an extraordinary amount of funds to the king, and they would gain a very advantageous control over customs as a means to collect repayment. This involved Riccardi officials staffing the ports and directly receiving customs fees, as well as fines which other competing companies paid the crown. The post provides a few numbers on it, but to sum it up, the Riccardi would make about £10,000 annually. To put that into scale, a 1287 campaign into Wales by Edward costed around £10,000 as well, which the Riccardi, incidentally, had provided £8,000 towards. Furthermore, in their about 20 year relationship with the monarchy, the Riccardi had loaned out a minimum of £400,000, so this was a very beneficial business deal for them.
Of course, I did say that the English kings constantly brought new bankers in and out, and the Riccardi would eventually fall from grace in the eyes of the crown. However, Edward didn't actually fail to pay back his loans at all, and if anything, this was the fault of the Riccardi. What happened was a perfect storm in 1291 where thanks to several seizures under the French king Phillip IV (About £11,000) and a Papal recall of funds (5,000 florins that would be increased to 80,000 in 1295, though after they lost favor with the English), the Riccardi were somewhat strained at the time. But the real stress came from Edward's attempt in 1291 to organize a crusade, requesting 100,000 marks (£66,666, mark = 2/3 of a pound) as merely the first initial half of the loan. Surprisingly, the Riccardi, though in a delicate situation, were still ultimately stable, but then in 1294 Edward declared war on France, and then floodgates opened up. I unfortunately don't have this number on me, but because of everything that I earlier said, the Riccardi could not supply a satisfactory amount and were completely ousted from their position from the crown. Long story short, the company was over. Just to show this, the last extant letter of the Riccardi comes at the end of the century (Sorry, I don't have the book on me so I'm using an earlier paper I wrote using it which didn't include the year) desperately requesting for a mere 50 marks (£33) and four lambskins from London for clothing.
What I want to point out with this twenty year enterprise, is that the monarchs were not always the villains who refused to pay their loans out of greed. Instead, with the case of the Riccardi, the bankers were the ones who failed to provide sufficient funds (Albeit, out of bad luck) and went out of business as a result.
Edit: Forgot to mention my main source, placed it at the top
I can answer this question mostly from an English perspective, in particular from the position of the Medieval Mayor, aldermen and guilds of London. The mayor and aldermen of London frequently gave the medieval Kings of England loans at favourable rates and large 'gifts' to keep him sweet.
Why do this?
Factor 1: Power disparity.
Simply put medieval society was geared around land and agrarian wealth - the king and his nobles, being top of the feudal pyramid with large estates and resources could simply expect the obedience and financial support of the emerging middle classes/professional classes in the cities. In terms of realpolitik the king and nobles had large amounts of men and weapons on their side while the city had a militia of shopkeepers at best. This also applies to large trading companies - a small band of mercenaries defending company property would be no match against a force of royal knights. Cities and companies in less settled realms were frequently looted by roving bands of soldiers loyal to one noble Lord or another.
Factor 2: A quiet life and access to the law.
The king keeps the peace and enforces the law. As a merchant house, or civic corporation you need peace in the realm and access to legal mechanisms to trade. There was an extensive legal system in England in the late middle ages - but it was very much the King's law. Law in late medieval England was based on judgements made by following the judgement of previous royally appointed justices of the peace and whatever new royal decrees were issued by the reigning monarch.
Annoy the king too much and he could simply order the courts to judge against you, or at least make laws that restricted your ability to trade with foreign powers or in certain goods. Magna Carta in England did a fair amount to curb this royal abuse of power but it still went on fairly regularly in the high middle ages.
Factor 3: Privileges.
Keeping the king and his nobles happy by giving them your lovely cash allows you to enjoy perks. London merchants, for example, could trade in the rest of England without having to pay taxes. Calais merchants (Calais was a part of England during the middle ages) were given the monopoly over the English wool trade under Richard II. Individual merchants or companies could be given monopolies on importing or manufacturing certain items.
Giving the king a lot of your hard earned cash could also result in the king spending a large proportion of that cash with your company on things he wants that you provide to him - essentially you recoup some of your fiscal outlay by having the king buy a lot of your goods.
Factor 4: Patriotism/ general willingness to lend.
Sometimes the King or nobles did things that seemed in the national interest or that were popular with the citizenry. Usually in England this involved invading France. Londoners were fairly happy to loan the money to the war effort - with the idea that the return was hypothetical based on the success of the war.
Also don't forget that disloyalty to the crown or war effort was treason and punishable by death... so obviously many companies and civic bodies would loudly trumpet their loyalty and swallow any losses if the king started loosing the war!
So in summary:
The king provided a good trading environment for companies, allowed access to legal mechanisms to traders and guilds and granted privieleges to those who loaned him money. Also dont forget that companies then as now needed a good public image - and often gained a considerable public relations boost from seeming patriotic and loyal by loaning money to the crown.
Regarding my sources:
The city of London corporation kept extensive records on its civic rolls of all transactions relating to civic business and you'll find that many of the individual guilds also kept account books - that are usually named after the colour of their bindings. For example the pinners guild (who made pins) kept a white book that detailed their business. These account books (though a little dry) to read offer a good, fairly objective overview of both the city's accounts and the deeds of the various guilds and aldermen.
Additionally you have several contemporary chroniclers who wrote about civic patronage of the crown. These chroniclers generally like to focus on the royal court and less on civic matters but they provide a good analysis of the relations between city and crown. English historical writing really came into it's own in the late middle ages and the chroniclers, though they didn't have formal training, do valiantly attempt to discern the reason for events (beyond the typical professions of loyalty to the crown by the merchant guilds) which helps the modern reader a great deal.
Beyond primary souces, a good secondary source to look at is 'London in the Later Middle Ages: Government and People, 1200–1500' by the respected historian Caroline Barron. It's full of detail and Prof. Barron's commentary is invaluable.
Joachim Voth and Mauricio Drelichman answer this question for the case of Phillip II of Spain, who is the poster child for serial sovereign default in the early modern period. (For an excellent summary, see Regina Grafe's review here: https://eh.net/book_reviews/lending-to-the-borrower-from-hell-debt-taxes-and-default-in-the-age-of-philip-ii/) What they find is that both the market structure of banking (effectively a syndicate) and the contractual structure of the debt (the asientos) was set up in order to accommodate the possibility short-run default, while maintaining the long-run sustainability of the debt. Both the expenses and revenues of the King were highly variable, and not well correlated - a good year for taxes was unlikely to be the same as a bad year for expenditures. And so the only way to consistently meet spending needs in the short run was through borrowing. This is what economists call "smoothing." Everyone involved was aware of the fragility of the King's annual finances, which depended on annual shipments of new world silver. Any disruption to that income flow could prevent the King from paying.
However, the King could still theoretically cheat by defaulting on existing creditors and borrowing from new ones, using his power as a large sovereign borrower to undercut his existing creditors. To prevent this, the Genoese creditors created a syndicate who banded together in order to enforce their threat: no further lending in case of default. They sanctioned anyone who would lend to the Spanish king while the monarch was in default. This forced the King to make up lost payments, and disincentivised strategic default, as opposed to default from necessity. In exchange for continuing to lend, they received a risk premium commensurate with the possibility of (temporary) default. Lenders knew they would continue to profit from being bankers to the King, able to lend at high rates in large amounts. They also passed on much of this debt by selling it on to others, operating not unlike underwriters in the 19th century. The strategy was overall successful. The Spanish monarchy was not a long-run defaulter; it made good on its debts despite any temporary shortfall.
Source: Voth, Hans-Joachim and Drelichman, Mauricio. Lending to the Borrower from Hell: Debt, Taxes, and Default in the Age of Philip II. (Princeton, NJ: Princeton University Press, 2014)