Judge Masipa ordered the South African athlete to spend 30 days having mental health evaluation before his trial for the killing of his girlfriend Reeva Steenkamp could proceed.
She said the aim is "not to punish the accused twice. If there is a possibility of making sure he is an outpatient, that's preferable".
Paralympian Oscar Pistorius will spend the next 30 days being evaluated
The judge added that the psychiatric evidence already presented to the court could not replace "a proper enquiry" into the double amputee's mental health. He is now headed to an outpatient facility in Pretoria.
His defence team had vigorously resisted the prosecution's application for the assessment.
Prosecution lawyer Gerrie Nel filed the request on Tuesday after a forensic psychiatrist appearing for the defence testified that the Olympic sportsman was suffering from Generalised Anxiety Disorders (Gad).
Fans have gathered every day to give him their backing
Prof Merryll Vorster said that Oscar's background - the amputation of his legs as a baby, his family's heightened fear of crime, his parents' divorce, his mothers death when he was 14 - combined to bring about the disorder.
This would explain, she said, his extreme reaction on the night Reeva was shot.
The athlete denies intentionally firing on his girlfriend through a locked door in the early hours of Valentine's Day last year. He has said he mistook her for an intruder.
Under South African law if a defendant is alleged to be mentally ill or not criminally responsible then such an evaluation must take place. Legal experts say the outcome of the case will most likely hinge on the judge's understanding of his mental state when he pulled the trigger.
Although the decision came as a surprise to most people in court, the Pistorius family did not appear disappointed.
Speaking outside the athlete's uncle Arnold said they were "comforted by the thoroughness and detail of this judgment".