In many places the mentally ill have not been treated the best throughout history, and Japan is probably no different, but the way it handles mental illness today is a result of the influence from many other nations. There are many resources available to help a suffering patient here.
Before the Meiji Restoration, Buddhism and temples were the major players in taking care of the mentally ill. Chinese herbal medicine, kampo, was also commonly used, and is still used today to treat a wide variety of illnesses other than mentally related ones. After the Meiji Restoration in 1867, the Meiji government adopted Western medicine. A lot of changes have happened since then, but Japan today has more than 1,000 psychiatric hospitals with around 300,000 beds.
I have never personally been to a psychiatric clinic, but from reports the general process is rather simple and straightforward. You can go to a clinic, with a consultation usually lasting around 30 minutes, and depending on how the physician judges you, you will be prescribed drugs. They can be antidepressants or some other type of drug. You can then go to a drug store to pick up those drugs, and it is all generally inexpensive.
Japan has a high rate of suicide, one of the highest in the world. In order to combat this phenomenon, Japan has a hotline for people who are having suicidal thoughts. They can call and consult with a trained teller, who will guide them and attempt to get them help.
There is also quite a bit of mental illness among the homeless population, although it is unclear whether the issues started due to homelessness or whether the homelessness was a result of the mental issues themselves.
There is also a severe mental illness that involves the fear of social interaction with anyone, leading to people confining themselves in their own home and out of contact with others for months or years, called hikikomori. This is one of the most serious and infamous mental problems that Japan deals with.