Why does "whence" have "when" in it?

Solution 1:

Whennes is the later (c1300) genitive of Hwanone, which according to the Online Etymological Dictionary is a related form of hwaenne, or the ancestor to when.

Genitives indicate origin, place, and possession (or circumscripture) of a noun. According to the dictionary, the -ce is what indicates that this is a genitive of a root word.

So when was apparently the same or a closely related word, but whence is a holdover of an ancient genitive case which English doesn't have, any more, so the syntactical distinction that once clarified the relationship between when and whence has been lost.

Once upon a time, though, the relationship was clear: one was a standard form of when, and the other was its genitive, or in other words, when, but applied to space, with respect to origin.

Solution 2:

There is no relation between the origin of when and whence.

The origin of the words reported by the NOAD are the following.
Whence comes from the Middle English whennes, from earlier whenne (from Old English hwanon, of Germanic origin) + -s (later respelled -ce to denote the unvoiced sound).
When comes from the Old English hwanne, hwenne, of Germanic origin.