Loaned money is not created out of thin air, they represent liquidity transformation of illiquid future cash streams of creditor into liquid deposit (Rendahl & Freund, 2019).
In addition to the above, every time bank issues a loan it is by law required to hold some liquid assets like bonds or excess reserves. Most of these are nowadays borrowed from central banks but deposits can be used as well. These are also moved between banks as banks settle various transactions between themselves. If the financial outflows (e.g. people withdrawing money) exceed financial inflows (e.g. people repaying their loans) then bank will need to start getting into its buffer and once that is exhausted bank becomes illiquid and eventually insolvent.
Example: If a bank gives someone a mortgage and that mortgage loan is created out of thin air. When the borrowers default the bank gets a free house which they can just sell and make a massive profit.
Nope, they can't make massive profit. They can only make profit if they somehow manage to sell that house at higher value than was the mortgage. When banks creates loan which is asset for a bank there is matching liability in deposit that the creditor has at its disposal. If the creditor defaults on a mortgage bank still has that loan as an asset deposit as a liability. Repossessing and selling the house just reverses this process and basically 'cancels' the asset and liability. If the bank sells the house for less than mortgage value they actually record a loss if more they record profit if for the same value they have neither loss or profit.
If there would be no collateral like house with mortgage bank would have to write off the whole unrecoverable value of the debt as loss.