The better way to do this is to delay payments until the future. Very common with stock options for executives at public companies that vest over time
For example, you could negotiate NIL where a player gets $200k upfront, and $200K more if they return for another season. They would forfeit the $200k if they transfer, and get something in between if they go pro... this is thinking out loud, and could refine to something better
When schools think about ROI for someone they consider to be a 2-4 year player, they would probably pony up more money to get the full life cycle. Not to mention identifying undervalued talent, developing players, etc.
Otherwise players will still transfer and deal with the consequences later. As many posters said, these agreements are very difficult to enforce