A prime example of this is the Virginia Tech shooting. Despite being obviously threatening and clearly mentally disturbed the shooter was released as an outpatient with no follow up. He skipped treatments and ended up killing many people. If a doctor sees that a patient may harm themselves or others, they have a responsibility to take steps to remove that person from society.
Besides that not every act of gun violence is due to mental illness. We give mental illness too much credit. What about people who just do bad things? The narrative of "mental illness" when overpromoted encourages people to deny personal responsibility and just think "well, my brain is screwed up, can't do anything about it, guess I'll just go crazy" rather than trying to be responsible and control their behavior. Sure a person could also see a therapist, but a lot of people think "well, why is my brain being judged by society as any worse than anyone elses" they become defensive, their "illness" turns into a sense of personal identity and they become resistant to changing behavior which sometimes is do at least in part to illness but in other cases is just do to bad values, bad habits, bad beliefs. Too often I see when people ask questions about personal problems responders jump to conclusions of some sort of mental disorder. That should never be the first assumption. That you are making mental mistakes that can and should be changed should be the first assumption. Failing that then we can start asking about mental illness.
As to privacy or institutionalization it's similar to the principle that better 100 guilty men go free than 1 innocent person go to prison. There are many cases where a person might think subjectively "I'm worried about this person's behavior" but they could be wrong. Sometimes people are just odd.
I think a psychiatric doctor ought to be bound to report situations in which the patient might be violent, but they have to struggle with those questions themselves because they might do further damage to their patient if their relationship of trust is at question. Violent and aggressive people act out in all sorts of ways. It seems absurd that a doctor should be responsible for the actions of a patient and report all suspicions of possible violence, are we to make them responsible for knife violence, car violence? We need gun control...it would be simply going down a maze to try to attach responsibility to some professional when their client does something violent.
Doctors are extremely limited in what they can share and for good reason. Like most protections of the individual society pays a price for them. Blaming the doctors for following the law is insane if you want the doctor to be able to tell the problems of others be prepared for him to share your problems as well.
As far as gun violence goes, it is not a doctor's responsibility to prevent. It is his responsibility to diagnose and asses a person's mental illness and report it to the patient and if severe enough to their caretaker. If there is no caretaker, it is their responsibility to alert the state if they believe it is severe enough but people have their own free well. A doctor cannot be blamed if their patient goes home from an appointment and snorts cocaine or robs a bank and it is in the same regard not their responsibility to manage their violence; only to report. It is the state's responsibility to deal with the report.