Once upon a time, in the olden days (at least 25 years ago) you went to the bank for a mortgage. The banker checked your finances, and your down payment and gave you a fixed-rate, 30-year loan. Then they filed the documents away in the basement and sent you a bill every month for the payment.
And in the olden, olden days (about 50 years ago) your grandparents celebrated paying off their mortgage with a quaint "mortgage burning ceremony," throwing those paid-off documents into the fireplace.
Now we're in modern times. To get a mortgage, you didn't need a down payment, you didn't need much documentation of your finances, and you didn't need to know your banker. And your loan didn't necessarily have a fixed rate, or a fixed repayment schedule. That would be adjusted later, based on changing global interest rates.
Brokers competed to make mortgage loans and earned a commission on every deal they sent to a financial services company or bank. Those banks didn't store your mortgage in their vaults; they packaged it up with a bunch of other mortgages and sold them to investment banks. The investment banks found investors to divvy up these hundred-million-dollar loan packages, each buying a piece of the new "mortgage-backed security."
And some of those loan packages were different kinds of loans, blended together, then sliced like a meatloaf, and served to investors (banks, pension funds, hedge funds) around the world. So the first principal repayments on your loan went to one investor, while the last payments would be owned by another investor willing to accept more risk.