EXCLUSIVE

Grimes had a bizarre, unwanted visitor show up in her backyard -- wearing a cape, no less -- and now the man's been ordered to stay away from her.

According to new legal docs ... the singer and reported girlfriend of Elon Musk had an intruder at her home on July 10 named Raymond Barrajas. He allegedly scaled a hill at the back of her house while wearing a weird costume and carrying 3 computer mice.

The docs say he yelled out that he needed to see Grimes so he could "take her on a ride." She wasn't home, but her brother was and called 911. When cops arrived, Barrajas was still in the backyard and was yelling, "I'm a black man, shoot me."

According to the docs ... he was taken into custody and placed on a psychiatric hold. Grimes is worried the man has a delusional fixation on her and that he believes she is sending him messages through her music ... so she went to court to get protection from him.