The 28-year-old unemployed carpenter, Paul H., had used a survival knife to stab and slash his victims at Grafing railway station east of Munich in May last year.
The court found that “the accused suffered from a bipolar affective disorder, that was accompanied by psychotic symptoms at the time of the act”.
He was therefore “not criminally culpable” at the time of the attack, the court said.
The assault had sparked initial fears of a jihadist assault, but it later emerged that the man suffered from mental problems.
Paul H. has been held in a psychiatric hospital since the attack.