The Second Amendment says that the right to bear arms is necessary because of the need for a well-regulated militia.
So, make it so that everyone who wants to buy a gun has to be a member of a specially-designed National Guard auxiliary unit.
When a person buys a gun they can't take delivery personally, it has to be first shipped to the closest National Guard armory.
In order to pick up the purchased gun, the buyer has to travel to the armory, get training and a mental health check, and sign up to be a member of the auxiliary.
Like every other member of the National Guard, auxiliary members have to show up to the armory once a month for a muster. Everyone at the muster gets a weapon check and a mental health check. This is the only responsibility for members of the auxiliary.
Everyone caught with a gun who is not a member of the auxiliary or hasn't shown up for musters can be charged with desertion or failure to report for duty, and sent to a military prison if convicted.
This should eliminate everyone who doesn't want to be a responsible militia member from gun ownership.