The value of the sexp you passed as its second arg is the symbol delete-trailing-whitespace,
because the arg to when is a non-nil list (because you quoted it). So the when condition is always true.
And you never invoke function delete-trailing-whitespace; you just return the symbol that names that function.