It depends on the type of mortgage lender.
So you get deposit taking lenders vs non-deposit taking.
So this vary say from your small more traditional building society that probably only well lend out on mortgages their savings (eg savings accounts people have with them) they pay 3% interest on their savings, charge 5% interest on their mortgages = profit. Simple.
Then you get high street commerical banks like Natwest for example, also deposit taking so work in the same way as above, but the likes of Nawest will also trade in investments or borrow money themselves to lend at a higher rate then they borrow.
Then non-deposit taking lenders which is like the one I work for, we do not offer any savings accounts at all, so all the money we lend in mortgages is borrowed ourselfs.We typically borrow this in tranches at a fixed rate so, £25m at a time, and then lend in out at a higher rate (or try to) and pocket the difference. We then do whats called securitisation, which is a simply as I can put it, is we take all our live mortgage accounts, and put them into a seperate limited company, these are then externally audited. Provided that is ok, we then sell this limited company and all its live mortgage accounts and a mortgage backed security, or a longer term investment.
The entities that buy and sell these tranches of money or securities can be anything, from very wealthy individuals, other banks, pensions funds etc. It's all just money going around in a big circle and trying to make a margin each time.
What cuased 2008 and what the concern is this time (mainly due to the Ukraine war) is if this circle of money suddendly stops, the whole thing falls on its arse and collapses. It only takes a few of these to stop lending to each other out of fear, and wanting a return on their capital, for everything to snowball.