I think you hit on the major problem with (US) gun laws. There are something like 300M+ guns in the USA. Supposedly, those are guns in circulation. i.e. Not sitting in a warehouse or on in a gun shop display case.
It is an easy thing for anyone to obtain a gun illegally for illegal purposes. It is somewhat less easy to obtain a gun legally for legal purposes.
And it's only moderately difficult to modify a legally obtained gun to exceed the parameters that make it legal.
Larger magazines, modified lowers and uppers, mil-dot scopes, and general tweaks can turn any gun into an "assault weapon".
As to the mental stability, the US has a bad track record for dealing with mental issues. Even today, it's hard to get good mental help. You could self-identify today as a potential danger to yourself or to others and it could be 2+ years before you are stable.
And that's for someone who wants to get help. Most don't.
I disagree that we need a gun that can determine if you are mentally compromised. It's just too "sci-fi" to be viable. What we do need is a way to track guns from cradle to grave and hold the registered owners accountable for illegal use.