In the current version of Dwarf Fortress, there are seven events that can cause a unit to go insane, and 4 of those can be experienced by members of your fortress - a strange mood being forcibly cancelled due to workshop deconstruction (or magma forge losing power), a strange mood timing out (from being unable to claim a workshop or collect all of its items), extreme drowsiness (over 6 months without sleeping, which can really only happen if you lock the dwarf in a room filled with traps since they'll refuse to go to sleep and trigger a trap), and prolonged unhappiness (throwing one too many tantrums in a short period of time)
if the dwarf has not completed strange mood.
If a dwarf completes a strange mood and creates an artifact, then even if they become Miserable and repeatedly throw tantrums, they
will not go insane (unless they're kept awake for 6+ months). Dwarves which haven't completed a strange mood have a chance to go Insane each time they decide throw a tantrum - the actual mechanics are described
here, based on studying a disassembly of the relevant code. Incidentally, this logic has existed since the earliest versions of Dwarf Fortress released, albeit less complicated back then (e.g. back in 23a, it didn't look at personality traits because they didn't exist yet).