Mubashir Jamil, 22, of Luton, was arrested last April after chatting online with a covert police officer.
The prosecution at his trial at the Old Bailey said Mr Jamil would claim he sought to join the so-called Islamic State group (IS) to exorcise "evil spirits" that plagued him.
The accused denies the charge.
The court heard the former straight-A student had become obsessed with the idea of martyrdom after surfing the internet for IS propaganda.
However, he was caught after talking with an undercover officer using encrypted messages on an app.
Mr Jamil had allegedly offered to put on a suicide vest and "press the button on the same day".
He was arrested by counter-terrorist officers a few days before a planned flight to Turkey.
The jury was told Mr Jamil had planned his trip carefully and "deliberately" changed his appearance.
They heard how he shaved off his beard following guidance in an online publication on how to be a "secret agent" in a non-Muslim country.
Mr Jamil, who was born in Pakistan but brought up in Britain, denies one count of preparing for terrorist acts.
The trial continues.
A man accused of preparing for terrorist acts by trying to travel to Syria was obsessed with martyrdom, a court has heard.