In simple terms, It's something to do with type definitions and what is supported by the subtract operator. Typically objects don't know how to be added/subtracted from one another however some objects (like Date) have a prototype named valueOf that is automatically executed by the V8 engine (under the hood) when you try to run d1+d2
As for whether Monaco should know about this or whether it is a deliberate "good housekeeping" measure - I don't know. I'll look into it some time.
Essentially, you are subtracting numbers so use valueOf...
msg.payload = d2.valueOf() - d1.valueOf()
... Or coerce the type using jsdoc like Julian shows.