Who decides who is qualified?

The problem with that adjective is that it can easily be reversed to decide that Americans are not qualified if - they a conservative or a liberal, religious or atheist, a drinker, a toker, or a teetotaler, short or tall, served in the military or was a conscientious objector, is a police officer or not ... and I could offer a hundred more examples.

Does the guy who sought counseling for depression after his 20-year marriage dissolved qualify to own guns or is he disallowed because he recognized a problem and dealt with it?

Is the retired soldier allowed to own guns because he served his country or is he disallowed because he might have PTSD?

The felon who got selling cannibis at 18 is apparently disqualified, but the cop with anger issues and 15 excessive force complaints in his packet is qualified.

Who decides who is qualified and what qualifies them to make that decision on restricting a fundamental right?