Dishonorable Discharge
If the military considers a service member's actions to be reprehensible, the general court-martial can determine if a dishonorable discharge is in order. If someone is dishonorably discharged from the military, they are not allowed to own firearms according to U.S. federal law.
According to Military.com, here is "Everything you need to know" about a dishonorable discharge. Those who have received a dishonorable discharge, the U.S. government does not legally consider a service member a Veteran, and therefore they generally cannot receive most Veterans benefits. This includes federal benefits and many on the state level as well. One thing a service member/Veteran can do to potentially remedy this is by applying for a discharge upgrade. ​​​
The Veterans Advocacy Project 's Discharge Upgrade Clinic fights to restore honor to Veterans who were unjustly discharged. Their team files applications for upgrades and corrections while also training and supervising a network of attorneys representing Veterans free of charge in their applications before the Department of Defense. ​​
​​The Veterans Consortium (TVC) offers offers free nationwide legal assistance for discharge upgrades for Veterans who have been discharged with an "Other Than Honorable" discharge due to a mental health condition, such as PTSD or traumatic brain injury; for military sexual trauma victims with less than honorable discharges; and for Veterans discharged for homosexuality. ​​​​