It's a way of criticizing something in a humorous way.
Jim and Huck discuss King Solomon satirically, criticizing and stimulating humor. This provokes the reader's reflection, making him think about the subject more lightly and understand the ridiculed subject in a light way.