Can anyone confirm whether Section 31 ever appeared in a Star Trek: The Next Generation episode?
They did not. The organisation was invented for the DS9 episode Inquisition, broadcast 4 years after the last episode of TNG.
Q. Was there any debate about whether or not to establish that [Section 31, in "Inquisition"] has been around for so long?
A. We had extended conversations about the backstory to Section 31 and yes, there was a lot of debate about how long and under what circumstances this branch had existed.
That being said, Section 31 comes into conflict with the crew of the TNG Enterprise a few years after Nemesis in the EU novel Star Trek: Section 31: Control.
Data felt great pride at the progress his daughter had made in so short a time. When he was her age, he had still been struggling to master basic interactions with organic sentient beings. By contrast, Lal meshed easily with organic beings, and in spite of what Data had originally considered her fragile emotional state, she was demonstrating tremendous calm and poise in the face of a serious and perhaps even existential threat from Section 31.
2veeery tenuously one might with a good bit of tongue in cheek say that the answer could be yes, in that Dr. Bashir appeared in TNG (albeit prior to his joining Section 31) :D Apr 10, 2019 at 16:38
While true, the fact that it canonically existed at that time had let fans into thinking that various people or plots might have involved Section 31, just under cover.– trlklyApr 11, 2019 at 1:21
As @Valorum already stated, 'Section 31' as a department was thought up during DS9's run, but in-universe the organisation, or specifically the article in the Starfleet charter that lends its name to the covert-ops branch, has existed since the very beginning. Here's a quote from the Star trek: Enterprise episode Divergence, where Phlox is ... involuntarily re-assigned.
ARCHER: Phlox was kidnapped. Starfleet would never authorise that.
HARRIS [on monitor]: Reread the Charter, Article 14, Section 31. There are a few lines that make allowances for bending the rules during times of extraordinary threat.
4The strange thing is that it was a super-secret division in DS9 time, but everyone on Discovery seems to know about it, in pre-TOS time.– BarmarApr 10, 2019 at 22:35
Don't try to make sense of the greater lore given things revealed in discovery, it's likely to be all ret-conned by time travel shenanigans so the writers can say "SEE WE WERE RIGHT ALL ALONG" at the end– JoshApr 11, 2019 at 7:06
2@Barmar You may be jumping the gun, here. With the way events are escalating in this end of Season 2 for "ST: Discovery", Section 31 might have any number of major setbacks and reorganizations. By the time 100 years go by when we see them in "ST: DS9", it might be entirely plausible they've evolved into this "rat in the walls" agency. Even without any cataclysmic events, 100 years could see charters and protocols change.– BlazeApr 11, 2019 at 21:34