A terrorism suspect arrested outside Buckingham Palace had first wanted to go to Windsor Castle, but his satnav instead took him to a pub of the same name, a court has heard.

Mohiussunnath Chowdhury, 26, was detained outside the royal family residence in central London last Friday, allegedly having a four-foot sword and saying “Allahu Akbar” as he was arrested by police.

He appeared at Westminster magistrates court on Thursday accused of a single offence of preparing to commit an act or acts of terrorism. The incident is alleged to have left three police officers with minor injuries.

It is alleged that Chowdhury, 26, who works as a self-employed Uber driver, had set off from his Luton address about two hours before his arrest and he used his satnav to try to drive to Windsor Castle. After he arrived at a pub of the same name, he drove on and eventually ended up near Buckingham Palace in central London.

He is alleged to have then driven towards a marked police car in a blue Toyota Prius at just after 8.30pm on Friday and stopped. During the incident, he was sprayed by police with CS gas and arrested.

The court heard that Chowdhury, who wore a grey tracksuit and spoke to confirm his name and address, was remanded in custody. He will next appear at the Old Bailey on 21 September.

After the incident, royal officials said no members of the royal family were in residence at Buckingham Palace when Chowdhury was arrested.

He is a British citizen and the formal criminal charge laid before the court allege: “On or before 25 August 2017 Mohiussunnath Chowdhury engaged in conduct in preparation for giving effect to his intention to commit an act or acts of terrorism, contrary to section 5 of the Terrorism Act 2006.”

Chowdhury was detained at Constitution Hill, near to Buckingham Palace, by the officers from the Metropolitan police.

The Met’s investigation was conducted by SO15, which is Scotland Yard’s counter terrorism command.

After the incident, police said that two of the officers were taken by ambulance to hospital with minor cuts and discharged a short time later. The third injured officer did not require hospital treatment.