In one of the Buffy episodes, there is a quick flash of a scene where she is in a mental hospital. Was it ever resolved why this scene was shown? I seem to remember the implication being that her whole life was a mental breakdown.
The episode you are referring to is "Normal Again". It isn't a "quick flash of a scene". The entire episode is a tug of war between her being in a mental institution (in which the doctor and her parents are trying to convince her that being a slayer is a delusion) and the life we are accustomed to seeing her lead in Sunnydale.
Ostensibly, the mental institution is the delusion (rather than her life as a slayer), and the visions of the mental institution are brought on after Buffy is stung by a demon, thereby exposing her to a hallucinogenic venom. In-universe, this is why we are seeing these scenes.
That being said, the episode ends in an ambiguous way, so as to suggest that her life as a slayer in Sunnydale might actually be the hallucination.
Out-of-universe, this is what led to the episode in question:
According to Joss Whedon, this episode was the "ultimate postmodern look at the concept of a writer writing a show", as it questioned fantastical or inconsistent elements of the show "the way any normal person would". Whedon added that the episode is intentionally left open to interpretation... "If the viewer wants," Whedon says, "the entire series takes place in the mind of a lunatic locked up somewhere in Los Angeles... and that crazy person is me." Although, "Personally, I think it really happened."