Palace police tackled David Belmar, a 44-year-old from north London, when they caught him jumping over a vehicle barrier near the staff entrance to Queen Elizabeth's London home. He had a six-inch kitchen knife in his pocket.
Charged with trespassing and possession of a bladed article, Belmar appeared before the Westminster Magistrates' Court on Monday.
Prosecutor Edward Aydin said that while in custody, Belmar told police: "I wanted to see the Queen. I'm not happy about my benefits."
Aydin also said that Belmar was taking medication for mental health problems and had a fixation with Queen Elizabeth. He was arrested in 1989 for throwing fireworks onto the palace grounds.
"As you can see he's quite a large man," Aydin said of the incident. "He was rugby tackled to the ground because he wouldn't stop. Police called out on two occasions."
The chief magistrate said that Belmar's past convictions made him "a danger not just to himself but to others."