It is part of the law. As an example, here's how Maryland's law works:
How do I request an emergency evaluation against an individual who is believed to have a mental disorder and presents a danger to the life or safety to self or others?
mdcourts.gov
What you post is true of Maryland, but each state has its own programs, laws, and procedures regarding mental health issues and protective orders.
Addressing this Maryland law specifically; - in reality the person who petitions the court to have someone picked up for an emergency evaluation will have to go in person to a jail or jail-like place and spend several hours filling out forms by hand, and then sit for another hour or two waiting for some commissioner (who they never even see) to sign off on them.
Then some time in the next 24 to 48 hours, the Sheriff will stop by to pick up the person for whom the evaluation has been requested, and transport them to a hospital with a mental health section. There they will be given tranquilizing meds and placed on three days of observation before being released back to their home or family with a bottle of prescription pills to take (or not). Three days is the maximum they can be held for observation unless they were to pose a clear risk to themselves or others in the meanwhile.
While these procedures and methods might be helpful to persons at risk, they do not in any way prevent the patient from purchasing a firearm later. This sort of hospitalization is not the same as someone being found guilty of a crime and sent to a mental institution as a result. It is simply an administrative procedure designed to get the person some hospital type assistance. And HIPPA regulations would prohibit release of any records on the patient.
Now Maryland DOES have a rather unique alternate court system known as "Mental Health Court", but it is completely voluntary. This is where someone is actually brought to trial for a criminal charge of some sort, and the Defense offers or suggests to the judge that the person is mentally ill - usually with some sort of evaluation or history to back it up. An example would be a charge of assault and battery where the accused became violent as a result of a mental condition.
In such a case, the judge can offer to the accused the option of participating in the Mental Health Court program, where he agrees to go to weekly counseling and take any prescribed medications. A counselor or probation officer is assigned to the case and he/she reports to the judge on progress. The accused goes to court once a month before the judge and reports in. During this period of time, the accused has to agree to not use or own any firearms, and there may be other restrictions as well, such as agreeing to stay away from certain persons, places, or situations.
After a full year goes by with full attendance and no further problems, he can graduate from the program. He still has the conviction on his record, but has served no jail time and after a few years, he can get his record purged if he has stayed out of trouble. It has proven to be a very effective program for many persons.
Again, this is voluntary on the part of the accused. If he turns it down, he can be sentenced to jail time, fines, and other restrictions based on the nature of his crime.