New York City judge Orlando Marrazzo ruled Kevin McGlynn was unfit to stand trial on stalking charges and committed him to a psychiatric hospital in Staten Island, reported Daily Mirror.
He told McGlynn to stay away from Rihanna's home in Manhattan and gave police officials permission to arrest him if he was spotted in the vicinity.
He has also been barred from contacting Rihanna by phone, mail or computer.
McGlynn, 54, reportedly wrote a series of notes to the singer that made references to murder and sexual assault. He also accused Rihanna of using his material in her songs and was spotted outside her home.