I am by no means an expert in pharmaceutical studies, but I suppose they can afford a huge number of dead ends in the initial phase of research due to the massive wealth and in the end, they have to test only for two variables: efficiency and side-effects. An explanation on how it actually works, is a very nice extra, but is not required. The problem for Pharma is that at some point you require tests on human subjects, which is very expensive and dangerous.
A lot of original psych drugs were also discovered by accident, intending to address some other medical issue. For example MAOIs were found to have antidepressant effects during a trial to use them for tuberculosis. Development of SSRIs (e.g. Prozac) then came from trying to create a similar drug with less side effects.
Also, the many dead ends thing is true in general for pharma, but at some point there are too many dead ends for it to be profitable even given their bankroll. This is happening a lot lately with neuro-related drug development. In the last 10 years I know Amgen, Pfizer, Novartis, Eli Lilly have all had shut downs/lay offs in their neuroscience research divisions.