What happens to an MBS if all the underlying mortgages are fully paid back by the borrowers much before the maturity date?
Depends on the structure.

In the US, most residential MBS are pass-through, so the MBS is prepaid.
In Canada, MBS are (or at least were) mostly packaged into non-passthrough structures, so MBS cash flows follow fixed coupon schedule. There are prepayment penalties which are used to absorb the cash flows.
My understanding is that European pfandebriefe markets use a collateral pool, which absorbs prepayments.