David Belmar, 44, had to be tackled to the ground by police after he jumped over a vehicle barrier at the north entrance of the monarch's official London residence in October.
A judge at Southwark Crown Court sentenced Belmar to 16 months in jail for possession of a bladed weapon and six months, to run concurrently, for trespassing on a protected site.
Belmar, from north London, pleaded guilty to both offences.
He had been on incapacity benefit for ten years but it was stopped after an assessment in September.
The incident came after a series of security incidents at Buckingham Palace, the main London residence of the royal family.
In September 2013 a man who scaled a fence to get into the palace was arrested on suspicion of burglary.
A few days afterwards, with security on high alert, jittery royal protection officers challenged the queen's third child Prince Andrew in the gardens of Buckingham Palace.
Fagan, who had climbed over the palace walls and scaled a drainpipe, spent 10 minutes talking to the sovereign before she was able to raise the alarm.
