The Metropolitan Police said Daniel Sheehan, of no fixed address, had been charged on Saturday.
He will appear in custody at Westminster Magistrates' Court on Monday.
No members of the Royal Family are thought to have been at the palace at the time of the alleged incident on Friday.
The Queen had undertaken an investiture ceremony at Windsor Castle earlier in the day.

First of all she was sacked as chair of a committee which gives advice on how millions of pounds of EU aid is spent in Wales.
And if that was severe, she responded in kind.
Most of those in Cardiff Bay appear to be genuinely surprised at the nature of the language she used in her statement.
It's been well documented but worth reflecting again on what she wrote: "The events of the last 24 hours have confirmed in my mind there is an unhealthy culture at the top of the Welsh government which does not allow for rigorous debate and reflection on the best use of public funds.
"Independent thought is not tolerated by AMs and if someone does step out of line, they are ruthlessly dealt with. This is not a good way to make difficult decisions."
Ouch.
Her fellow Cardiff Central politician, the Labour MP Jo Stevens, has come out in support but Labour AMs I've spoken to are not lining up to agree with her.
But was the decision to sack someone who you'd hardly consider to be a high-profile rebel an over-reaction by Carwyn Jones?
I'm told it's because this wasn't the first time she'd criticised government policy in public, and done it in a way which hadn't been reflected in internal discussions.
I took that to mean they didn't see it coming.
The sacking could also be a reflection of the sensitivity of the subject area.
Jenny Rathbone had described spending nearly £20m on preparatory work for an M4 relief road, before a final decision, as appalling.
It was interesting that in the Senedd this week Carwyn Jones was highly critical of the proposal for a cheaper alternative to upgrade the southern distributor road.
Until this point he has largely left the arguments on the project to his Economy Minister, Edwina Hart, but as a result of her decision not to stand next year I suspect we can expect the first minister to be more outspoken on the subject.
The Welsh government wants to show that it's deadly serious about the motorway, and while I'm told it wasn't foremost in the first minister's mind, the sacking of an assembly member for criticising the plan is one way of demonstrating that commitment.
There was a bad tempered exchange in the Senedd. The first minister insisted it was about a failure to follow collective responsibility.
The opposition parties were concerned that the chair of a committee that's supposed to scrutinise the way government spends millions of pounds of public money has been sacked for not agreeing with the government.
His response was to say that the committee she used to chair, the European Programme Monitoring committee, advises rather than scrutinises.
The Lib Dem leader Kirsty Williams asked whether her successor, Mick Antoniw, would be long in the job, considering that he holds similar views to Jenny Rathbone on the merits of a £1bn new M4 relief road.
Presumably he will have to bite his tongue on the subject now he's bound by the same rules as ministers in his job chairing the committee.
He told me earlier he wasn't afraid to speak his mind, but said that up until this point he'd managed to do so without waking up with a horse's head in his bed.
A 21-year-old man has been charged with two counts of trespass after climbing a gate at Buckingham Palace, police say.
[NEXT_CONCEPT]
Jenny Rathbone's criticism of Labour's plans for a new £1bn motorway around Newport certainly had consequences.