Sanity stat usually appear in RPGs focused on paranormal or horror themes.
Essentially is "level of purity" for mind, determined by actions/events influencing the player.
Typical ideas:
1.Stat starts with 100% of stat and reduces with negative events, recharges slowly and can be repaired with positive actions.
2.Each novel negative event(i.e. encounter) reduce sanity by the power of interaction.
3.Moral damage, each event where player is forced to perform a negative action reduces sanity.
4.Rest/sleep/healing replenishes sanity, as well as any positive action(defined by the game as positive)
5.Areas with negative or positive atmosphere slowly decrease/increase sanity.
6.As sanity reaches lower values, multiple negative debuffs begin affecting the character and player control is reduced.