Dennis Hennessy, 41, pleaded guilty to trespass during an appearance at Westminster Magistrates' Court.
He was arrested in the palace grounds on Wednesday evening. Police said he was not armed, and claimed security measures had "worked effectively."
Prosecutor Tom Nicholson told the court that Hennessy walked around the gardens for about 10 minutes toward the palace before being arrested. As he was detained he asked "is Ma'am in?" a courtesy term used for the queen.
Prosecutors said Hennessy was on parole after being convicted of the murder of a homeless man in 1992.
More From This Section
Judge Howard Riddle sentenced Hennessy to four months in prison for trespassing and two months, to run concurrently, for damaging an alarm system.
Several intruders have breached security at the queen's London residence over the years including a naked paraglider who landed on the roof in 1994.
In 2013, two men were arrested on suspicion of burglary, one in the grounds and one inside an area of the palace that's open to the public during the day.