This sutta tells the story of a time when the Buddha and around 500 monks stopped in the village of Sālavatikā while traveling through the kingdom of Kosala. This village had been given by King Pasenadi to a Brahmin named Lohicca. This Brahmin had a misguided idea in his head: that any holy person who discovers or formulates a good, skillful doctrine should just keep it to themselves.1 He had asked himself, "What good can one person do for another?" The conclusion he reached was, "none whatsoever." By Lohicca's reckoning, it would not only be useless for a holy man to try and teach others - it would be immoral! He felt that teaching someone a doctrine in order to liberate them from suffering is like freeing them from old chains only to bind them with new ones.
Despite his newfound conviction, when he caught wind of the Buddha's arrival in his village, along with excited gossip about how this ascetic had achieved complete enlightenment and become a great teacher of gods and men alike, he jumped at the opportunity to host such a beloved man and his order of monks. He ordered Rosika, a barber2, to go and visit the Buddha on his behalf. He wanted Rosika to politely check on Gautama's wellbeing, and then extend an invitation to a meal offering.
The barber did so, and the Buddha consented to the invitation in silence. That night, Lohicca had lots of food prepared, and the following morning he sent Rosika to retrieve the Buddha and his monks. While escorting them, Rosika spilled the beans to the Buddha, telling him about the misguided idea Lohicca had recently adopted. "Lord," he requested, "please teach him the error of such a thought!" The Buddha simply responded, "Hopefully he will come around, Rosika."
They arrived at Lohicca's house, and after the meal was finished, the Buddha cut straight to the point.
"Lohicca," the Buddha spoke up suddenly, "is it true that you believe someone who discovers a good doctrine should refrain from teaching it to others? Do you believe no one is capable of helping others?" The Brahmin confirmed, and the Buddha continued.
"Imagine if someone were to say, 'That Brahmin Lohicca should keep all of Sālavatikā to himself! All its land, and all the fruit it bears, should be his alone! It would be wrong for him to share these things with others.' Wouldn't this harm the people who depend on you and this village of yours? Wouldn't such a person be speaking with a heart full of hatred, and rooted in wrong view?" Lohicca considered this, and agreed with the Buddha. He continued, "Let it be known that someone who is rooted in wrong view sows seeds which they will reap in one of two pleaces: a hell-realm, or the realm of animals.3
"Imagine if someone were to say, 'King Pasenadi should keep all of Kāsī and Kosala to himself! Every fruit in the land should be his, and all revenue generated in the realm should fill his coffers alone!’ Wouldn’t that harm the people who depend on the king and live in his realm? Wouldn’t that person’s heart be full of hatred? Isn’t this person established in wrong view?” Again, Lohicca considered, and he agreed.
"In just the same way, Brahmin, this thought which has arisen in your head is harmful to those who would hear the truth taught by the Tathāgata. These people could be inspired to begin the path which leads to nibbāna, or rebirth in heavenly realms.4 Speaking in the way you have is harmful to them, and betrays a heart filled with hatred, and reveals that you are rooted in wrong view. As I said before, one rooted in wrong view is bound for rebirth in the realms of hell or in the womb of an animal."
"Lohicca, there are three sorts of teachers who should be corrected—in fact, if one should encounter such teachers, it is proper to set them straight. First, there are teachers who leave the life of a householder and take up the mantle of asceticism. Before reaching enlightenment, they prematurely begin teaching and accepting disciples. All of their students are unsatisfied and leave - yet still, they continue teaching! This sort of teacher should be reprimanded. They need to hear something along these lines: "You have tried to teach before discovering what needs to be taught! Your teachings have driven people away, yet you continue to teach! You are like a man who pesters a woman after she has rejected him. You are like a man who tries to hold a woman as she pulls away. Truly, this is a foul doctrine - what can you do for another?"5
"There are other teachers who likewise teach before reaching enlightenment, but they do not drive students away - rather, students flock to them and put their words into practice, mistakenly thinking they have found someone knowledgable. These teachers should also be reprimanded: "You are teaching these students without having discovered what needs to be taught! You are like a farmer who has abandoned his own field, overrun with weeds, to spend your time plucking weeds from someone else's field. Truly, this is a foul doctrine - what can you do for another?"
"Finally, there are teachers who have reached enlightenment. However, when they try to teach others, their students are dissatisfied and turn away, despite the fact that this teacher genuinely knows what needs to be taught. Much like the first kind of teacher, they continue trying to teach despite driving people away. These teachers should also be reprimanded: "You teach a legitimate doctrine, but it only turns people away! Still, you persist. You are like someone who cuts through the chains of a prisoner, only to try and bind them with a new chain."6
Lohicca asked, "Lord, is there any sort of teacher who does not deserve to be reprimanded like this?" The Buddha responds, "Yes, Lohicca, there is one sort of teacher who is worthy of praise." Here, the sutta presents the Sīlakkhandhavagga Pericope, describing the way a Buddha is born into the world, becomes enlightened, and teaches the path to enlightenment (along with all of the other things involved in the pericope).
Lohicca praised the Buddha, saying, "Lord, it's like I was slipping into a pit7, but you grabbed me by the hair and pulled me back to firm ground." He converted to a lay disciple.
The corresponding sutra from the Chinese Canon is Dīrghāgama 29. I do not have access to an English translation of this sutra. I will update this section if I ever get the chance to read it.
 I find this interesting. In this sutta, the Buddha is shown as flatly rejecting Lohicca's line of thinking - specifically, that someone who discovers or formulates a true doctrine should refrain from teaching it to others - as selfish and misguided. However, elsewhere in the canon (SN 6.1), Gautama himself is shown as having a similar thought after his own enlightenment.
The story goes like this: shortly after becoming enlightened, Gautama came to the conclusion that it would be fruitless to try and teach others what he had realized - it was too subtle, and the world was too mired in craving and ignorance. Trying to make others understand would just be a pain. He resigned to living the rest of his days in peace, until the time came to take his realizations with him to the grave.
A god named Brahma Sahampati detected these thoughts in Gautama's mind, and manifested before him in order to convince him to reconsider. He explained to Gautama (in beautiful poetic verse) that, while it was true that the world was mired in craving and ignorance, there were nevertheless people who were ready for his message - liberation was within reach for them, if only they had someone to lead them. Once more, the Buddha looked upon the world, this time using the power of his insight gained through meditation - he now saw the world like a great lotus pond, and even though some people were submerged beneath the mud, others were near the surface, ready to bloom. He responded to the god by saying (likewise in a beautiful verse) he had been convinced to teach anyone who would listen.
I see a few possibilities to explain this apparent contradiction:
A. one of these suttas was composed later than the other, by a monk who was unaware of the inconsistency these texts would introduce by being included in the canon together.
B. the story of the Buddha being inspired to teach by Brahma Sahampati is a metaphor. The author of this page, for example, suggests that Brahma Sahampati is meant to represent the Brahma Viharas.
C. the difference lies in the fact that Lohicca believed that teaching others would actually be a harmful/immoral act, while Gautama simply believed that nobody would understand; if this is the case, there is no contradiction.
 Barbers were considered to be among the lowest of the low-class, so we can assume one of two things: Rosika was bound to obey Lohicca either because he was something like a personal servant, or simply due to the fact that Lohicca was the Brahmin owner of the village.
 Walshe notes that this is indicative of the Buddha's hard stance against the belief that moral or immoral actions have no outcome (kammic fruits), something which he firmly condemns throughout the canon. However, Walshe also claims that there is some ambiguity in the Pali line for this statement about being reborn in a hell-realm or as an animal ("nirayam vā tiracchāna-yonim vā"), and that it's possible this could be read as "a painful or beastly rebirth." Likewise, he notes that descriptions of the hell-realms became increasingly detailed in later texts, but in the DN things are left vague.
Furthermore, he points to SN 36.4, where the Buddha declares that it is only out of ignorance that people claim there is a "hell" beneath the ocean. The Buddha rejects this idea, instead claiming that this "hell" should be understood as painful bodily sensations.
Walshe does not come right out and say it, but he is obviously implying that we should understand the Buddha's words here as being metaphorical. I disagree strongly. First of all, as far as I'm aware, the term "tiracchāna-yoni" literally means animal womb, and even though "tiracchāna" can be used as a harsh adjective meaning "lowly," I don't think it makes sense to read this figurative meaning into the word "womb."
Secondly, regarding the passage from SN 36.4, the word the Buddha uses when dismissing the idea of a "hell" beneath the ocean is "pātāla," which refers to a very specific location in Indian mythology, a place deep beneath the ocean where serpents live. The Buddha dismissing this idea in a specific sermon's context is not the same thing as dismissing the existence of hellish realms altogether - especially when we consider that the usual word used for hellish realms in Pali is "niraya," and not "pātāla."
Still, I should confess my own bias: I generally accept things like this from the suttas at face-value. I recognize the existence of metaphor and symbolism in the Pali Canon, but in my opinion, the idea of rebirth is usually presented quite straightforwardly and literally. I see no reason to be suspicious of mentions of hell-realms while accepting the obvious acknowledgement of heavenly realms throughout the Digha Nikaya.
 It should be understood that rebirth in a heavenly realm is presented as an obviously inferior alternative to enlightenment. Still, it's important to acknowledge this possible outcome of practice, because many laypeople practice with the goal of attaining a noble rebirth. This was true in the Buddha's time, and it remains true today in many Buddhist countries.
 Here, the Buddha used the same quote that Lohicca used above ("What can one person do for another?"), but it's obvious that this is being used ironically in order to demonstrate only bad teachers are incapable of helping others, and not teachers in general. I've parsed it a little differently because of this different context. This also comes across as a witty, light-hearted jab at Lohicca, a technique which the Buddha used quite often in debates.
 Here we have a Buddhist acknowledgement that it is wrong to force your beliefs on others, even if you're correct! An enlightened person is expected to acknowledge whether or not they're doing someone any good by teaching them. Implicit here is an understanding that sometimes it can do more harm than good to proselytize to an unreceptive audience. In other words, as Buddhists, we should never force our beliefs down the throats of others.
 Walshe notes here that the word for "pit" is "naraka," which can also be a synonym for "niraya," or "hell-realm." This line, then, is a symbolic call-back to the Buddha's earlier statement about how wrong view can lead to rebirth in hellish realms.