Fantasy and realism absolutely contribute to the humor as a man who is dissatisfied with his "real" life seeks the adventure and excitement of a "fantasy". By being able to pop into Madame Bovary and "play" a little, he escapes the hum-drum of his own life, but what's funny is that his fellow college professors recognize the odd little man who just shows up in the pages of the book as being none other than Kugelmass himself.
One expects that this "too good to be true" story will come to a screeching halt, although Madame Bovary proves to be a little high maintainance and readers realize that Kugelmass and his lover wouldn't last in a long-term relationship. It is suitable that the machine is blown up and that Kugelmass is stuck in a Spanish textbook with the hairy verb "tener" chasing him all over the place. This is the Spanish verb "to have" which is what Kugelmass is seeking--having the mistress of his dreams. Instead of having her, the "hairy" verb is determined to "have" him.
The tone itself is a sarcastic and humorous look at a man's mid-life crisis. You could find more examples that having an affair is not the thing to do in the face of a dissatisfied life. The boredom and nagging of Madame Bovary hints at this mistake, but the ending is an even more blatant warning against such straying. Perhaps therapy would be a better choice ?