Candy Spelling wants protection from a "mentally ill stalker" who allegedly believes he lives at Spelling's Holmby Hills mega-mansion ... this according to legal docs obtained by TMZ.
Spelling filed for a restraining order against 38-year-old Diyahml Farrakhan Muhammad -- a man Candy claims has trespassed onto her property at least nine times and "delusionally believes he personally knows and communicates with the Spellings."
According to the legal papers, filed yesterday in L.A. County Superior Court, Candy claims Muhammad thinks that her late husband -- TV icon Aaron Spelling -- contacted him "through the television" ... and invited him to live in the home.
Muhammad was arrested at Candy's home on August 31 -- and is currently on a 5150 psychiatric hold.
Spelling's top gun lawyer, Evan Spiegel, appeared before the judge yesterday and won the restraining order -- requiring Muhammad to stay 100 yards from the house and from Spelling.