Yes, this is legal: it would simply be part of the contract of sale for the house. Obviously, it may be tough to enforce--you'd have to know the amount he received for the house, and if he did not pay (if appropriate) the extra money voluntarily, would have to sue him for the money--but it is legal. A real estate attorney should be able to draw up a contract of sale incorporating this term.