I don't remember exactly. I would assume most would say "insane" people shouldn't have access to guns but like I said who decides what insane is? There's the fear that the government could easily class dissidents as mentally ill, that it's a slippery slope if you bar certain people from getting guns. So as long as someone hasn't engaged in criminality the regulations should be pretty loose. Another thing that came to mind, what about alcoholics? Reasonably you could assume they are more likely to do something insane, grab a gun when drunk. But then you run into the problem of determining who is a potentially dangerous alcoholic. We don't really have firearms here in Sweden the same way as the US but something interesting happened here recently. There is a lab marker that tells how much someone drinks and docs started checking that marker without telling the patient. The authorities started taking peoples' drivers licenses based on the marker after docs reported them, without them ever having driven when drunk and it caused a row. I think they changed that practice but it's maybe a bit like if you prevented "dangerous" people from owning guns.
I know many people who aren't really mentally ill but where I think them having guns might not be a good idea, simply because they are aggressive or really impulsive and emotional 
See that's nuts.
We have 330+ million folks, so we are never going to get it perfect. I threw it into grok just to see what qualified as "mental illness" and it gave me this:
Anyone who has been adjudicated as a "mental defective" (a term still used in the statute, meaning found mentally incompetent by a court) or has been committed to a mental institution.
So, it's obvious substance abusers, SSRI people, others etc can acquire. However, I can assure you that the overwhelming majority of firearms owners use them responsibly, which the math proves out by the fact that we don't live in an open war zone. But I can also assure those who own don't want lunatics owning them either.
How to guarantee this? I don't know. Might be impossible.