> mortgages which often come with an agreement that you won't pay it back within a number of years
Not "often". Prepayment penalty mortgages can exist but I've never seen or talked to anyone who has seen one in practice.
Some web searching suggests that only about 2% of home mortgages have prepayment penalty clauses.