Nutty as a fruitcake is used to describe someone who acts strange, eccentric, or completely crazy. It is a playful or humorous, rather than serious, expression for describing "nuts" or insane behavior.
The "Nut": In the 1800s, "nut" became slang for a person's head. Eventually, "nutty" meant someone was "off in the head."
The Cake: Fruitcakes are famously packed with literal nuts.
the adjective "nutty" (meaning insane) was first recorded in 1821, while the phrase comparing this behavior to a fruitcake (which contains many nuts) was first recorded in 1935 in the US. It playfullly suggests that just as a fruitcake is full of nuts, the person being described is "full of craziness."
While often used jokingly, the term "fruitcake" alone has been used as a slur in certain contexts historically. When using the full idiom "nutty as a fruitcake," it's best kept for lighthearted situations among friends.