Just a theory, but since the great Jerome Bixby shares the teleplay credit for this episode with D.C. Fontana, wouldn't it be possible that she's somewhat responsible for the shift in tone at the end of the episode?
Not to belittle Fontana's work (I've always been a huge admirer of her's), but the tone definitely doesn't befit Bixby's other efforts for the series, which were always more earnest in tone. The light tone actually seems more in line with Fontana's work.
So my theory is that there was a moment during the writing of this episode, where Fontana rewrote Bixby's script or "took over" from where he left. If true, I wonder what the original ending looked like. Is there someone here who knows more about what happened during the writing?
Anyways, "By Any Other Name" is one of my favorite episodes not only from the second season but the series as a whole. The Kelvans are good villains (especially Warren Stevens as Rojan), the pacing of the episode and the blocking of the scenes is wonderful. This is just one of these episodes I never get tired of watching.