As they are among the more representational mediums, and the more personally focused, both video games and tabletop role-playing games have a history of attempting to not only depict but to model mental illness. This is only right and understandable as this is what these games do; they take aspects of reality and model them in a way that allows us to experience them in a vicarious manner with more or less realism or slant depending on the design goals of the game
This process always involves some abstraction. In wargames berserk or otherwise uncontrollable troop types (whether through madness or stubbornness) are a common feature, especially in more fantastic rather than historical games. Usually each turn whether the troop obeys orders or follows its own whims is randomly determined, the reasoning behind this generally irrelevant. What those whims boil down to is also generally quite abstracted, as having to follow complex algorithms to determine the behaviour of troops that don't follow orders can break the flow of the game; the game is modelling combat rather than motivation after all. Similarly there will often be some level of fear response modelled, but this will usually be a part of a general morale mechanic as again we want to know whether a unit does what you want them to, not particularly what's going on in their minds at the same time.
When you start modelling individuals rather than groups motivation matters more, as does response to stimuli. Roleplaying itself, as a ruleset at least, developed amongst other things out of an attempt to model the actions of strategically important individuals like sappers within the context of wargames, although it quickly surpassed these beginnings. While early adventuring games focused generally on physical challenges, popularising the hit-point system as a way of conceptualising overall physical resilience, they tended to either sublimate mental resistance into the same pool or go for the all-or-nothing 'saving throw vs. x' approach (both of which are still present to this day).
Time now for a small digression on hit points. They often get a bad rap; as a storytelling tool they are ugly and confusing and mechanically there are a few glitches inherent at some of the extreme ends, as anyone who's had their Level 1 Fighter killed by a badger can attest to. The truth is they are an abstraction and a particularly numerical one at that but their elegance and continual popularity lie not in the way they model reality but the way they make the game play. It's all about the bookkeeping. I could probably write an entire article about the different ways of conceptualising hit point damage, but really that's down to how you tell the story in your game, from a practical point of view hit points are just easier to track than damage charts and less intrusive into the game than wound penalties. They aren't appropriate in every situation, but they are still functional in most.
It wasn't long before the burgeoning hobby started diversifying, with the horror-based game Call of Cthulhu introducing a separate pool of mental hit points termed 'sanity points'. Call of Cthulhu was not really modelling real life so much as modelling the books of Lovecraft, where contact with the Great Old Ones, their minions and their ilk eventually leaves characters either dead or insane; in this case insanity being a sort of catch-all debilitating state of mental degeneracy. In this context, terminology aside, sanity points are a really neat system, maintaining the same basic tension of 'this is how much further you can go before your character is unplayable anymore' that hit points provide but adding a second track to manage. Now going to the library can be as dangerous as entering a dungeon.
However, just as hit points can lack subtlety in interpretation, leading to characters who are essentially bullet-proof until they are suddenly dead so too can sanity gauges. On the physical damage front games have employed all manner of embellishments, from critical hit charts to permanent wounds, as a way of fleshing out that thin line between life and death. In games where one of the key innovations is continuity of individuals (as opposed to wargames where individuals are generally undifferentiated) then many have taken the position that losing one fight should not necessarily mean losing the game. This is where the idea of permanent mental disability as a punishment for, or at least a result of, failure emerges. It does so not, I believe, out of a desire to stigmatise or even make a point about how mental illness functions, but out of design choices based on modular thinking: this system works here so we can use the same mechanic here rather than try to introduce something new.
Essentially, if we're being generous, sanity mechanics like this are roughly modelling, or attempting to model, something along the lines of PTSD. But games love random tables and variety and so the urge has often been there to put in various different psychiatric disorders as possible consequences of failed saving throws or dropping below zero sanity or what have you, no matter what the real-world triggers and predictors for such conditions might actually be. As designers have started to realise that this lumping-together of conditions is not always very accurate we've since started to see discrete disorders either as pre-selectable traits or as specific responses to certain stimuli, alongside the continuation of a mental-resilience based model.
Video games, meanwhile, have long used the hit point abstraction as the underpinning of their damage mechanics for much the same reason: that it makes the coding easier. However, while in roleplaying it is possible to visualise the depletion of hit points not so much as actual wounds but as loss of stamina, damage to equipment and a general sense of using up your will or ability to go on, the intensely visual nature of video games tends to suggest that each blow that lands actually lands. This dissonance has of course got worse as graphics have got better.
When video games have attempted to portray madness through mechanics rather than narration it is no wonder that in general they have followed the sanity point model, for the same reasons that they tend to use hit points for health. Where they have differed from tabletop games is in the effects that depletion of these sanity meters have. Again the key is the visual nature of the games as well as the success they enjoy in hiding the workings of the algorithms from their players.
Zero sanity usually means a game over, either via catatonia, unplayable mania or or sometimes even the suggestion of suicide, and the decent into madness by necessity therefore is played out in the lower reaches of the sanity gauge. While a tabletop game might introduce madness through penalties or behaviour guides after the resolution of the traumatic event - after the failed saving throw indicates the final loss of control - in a visual game where the convention is to reset after failure the madness is often introduced as a feedback loop in that process of failing and presented through visual clues. In this way madness is presented and coded as glitch and hallucination in its entirety: to be mad is to see what isn't there, or maybe to see what is there and what others cannot or will not see.
Ultimately all of these approaches can be interesting, both mechanically and representationally, but they can also come with often unintended semantic baggage, implying things that are damaging and just untrue about the processes of mental health. they can also just be crass. I will leave you with the video games ur-example. Every sanity effect in Eternal Darkness: Sanity's Requiem, one of the first games to specifically model sanity loss as a visual phenomena based on a sanity point mechanic. It's just... crass really.