They work by utilizing Markov chains. Markov chains are like predictive text on your phones, where a markov chain looks at the subreddit and strings together two of the most likely words to actually be strung together in that subreddit, and it keeps stringing words together until there's a sentence. Of course, this is based on my understanding of it so it's not perfect.