It's pretty straightforward; it's a matter of "distancing and diluting" the dissonance.
This is "very dissonant"*:
... and this is "less dissonant":
The "clash" of the two notes has been reduced by distance. (Disclaimer: the explanation that follows may be inaccurate; the math confuses me.) Insofar as there is any objective math to "dissonance,"** that's because the first example has "beats" that are less frequent and therefore more noticeable. That is, when the two sound waves play at the same time, some times they "add up" to a louder moment and sometimes they cancel each other out. If we had this:
... then for each wave of the bottom C, exactly two waves for the top C would fit into it, and they'd line up nicely and sound "smooth." Or, if we had this:
... then both waveforms would be identical***; their peaks and valleys would line up, and we'd hear one pitch. But if we de-tune one C just slightly, then its wave would become longer; they'd start in sync, but every so often, after X milliseconds, it would wind up in a valley while the other one is in a peak, and they'd cancel out. And after another X milliseconds they'd be back in sync and reinforce each other again. At intervals smaller than a half step, the X unit of time can take so long that you can hear each individual "beat" and it can be quite noticeable. As the pitches diverge and the beats speed up, at some point we describe it as sounding "rough."
So anyway, the major 7th fits in twice as many Bs into each C, so the beats are more frequent, less additive, and less noticeable.
Meanwhile, making a seventh chord out of the whole thing:
... "dilutes" the dissonance because there are a bunch of consonances present as well. We could see this basically as a C major triad plus an e minor triad, superimposed. For modern sensibilities, both major and minor thirds are consonant, and we've got three of them! In subjective terms, the clash is "softened" by all these "nice intervals." (In some ways, this major seventh chord is even better than the dominant seventh because we lack the dissonant tritone we'd find between E and B flat.) In more objective terms as well, the other pitches add their interference patterns, and any beats between the C and B get softened by the interaction of all the other notes.
* But "as dissonant as it gets"? That's tricky, and depends on context and subjectivity. Plus, of course, if we step outside the equal-tempered 12-tone scale, for instance, two pitches separated by a quarter step will clash much more than a half step.
** There isn't always. "Dissonant" is a subjective and cultural word, and is also influenced by factors other than pitch anyway.
*** Theoretically, and especially if artificially generated. Things like instruments, human imprecision, speakers, and sound moving from the speakers through a room to our ears could make them not truly identical.