In your original code, the future generated by submit was not stored in a variable, and there was no reference to it after your function sub completed. Therefore, Dask will have noticed that no client is any more interested in that future, and it will have been cleaned from the system - probably it had already run, and the memory of the result will have been released.
This is expected behaviour, and deciding in your code which futures have references to them is a fundamental concept in managing memory on the system, see https://distributed.dask.org/en/latest/memory.html#clearing-data
I suspect that when yo originally called submit while not in a function, a reference to the result was kept by your repl - if you had added a ; to the end of the line to suppress output, you would have seen the same behaviour as calling sub.