Some “joke” writer came up with it in the first place. It went through executive layers before final approval by Letterman himself.
Letterman is one of at least several crude a$$holes at SeeBS.
As I understand it, Letterman rehearses the show with a live audience and then makes adjustments to the material before he shoots the actual on air show.
If true, he must have loved the audience reaction to keep the joke in his monologue.