If you loan someone money to buy a house, you are betting that either they will be able to pay or that the market will appreciate enough that all of the costs of foreclosure and resale will be less than the sale price of the house.
Both things being false at the same time in 2008 ruined Lehman brothers because they had the same thought you’re expressing here. Their gamble didn’t pay off.
During the subprime crisis, the entire US market went down by 30% and in some places sales basically halted for months. Many thousands of people lost homes, and almost all of them had equity on paper before the bubble popped.
Individual actions also matter. Maybe the reason you can’t pay your bank is because you developed a mental illness or drug problem, and they now need to replace a large amount of damage before anyone will pay what you paid.
Those aren’t constant high risks but they are why smart bankers calculate the odds and plan for what they’ll do when something inevitably goes wrong.
Just because the odds are currently in their favour, doesn't make it not a gamble.
It means the bank can be sure to recover their money and their costs.
That isn't a gamble.