A-level student Christian Mangles, 17, revealed the secret on Snapchat to an unknown friend on June 10 last year, telling the friend that he would take his own life if the secret ever came out.
The inquest heard police arrested and quizzed Christian - known as Kit - on June 13 for an undisclosed offence after being made aware of the Snapchat message.
The student at £34,000-a-year Ampleforth College near York was found dead inside his car the following day at at a beauty spot on the North Yorkshire Moors.
-> Wife admits killing husband in SheffieldHe died from a gunshot wound to the head, Northallerton Coroners Court heard.
North Yorkshire Police detective sergeant Michael Moorhouse, who gave evidence, said Kit was arrested at his home on the afternoon of June 13 after the contents of his Snapchat message was reported.
Less than 24 hours after he was released under investigation, Kit, who wanted to be in the army, travelled from his home near Whitby to a beauty spot known as Blakey Ridge and shot himself.
Assistant coroner John Broadbridge refused to tell the court the details of the secret.
He said: "On June 13 he was arrested on matters that I have deemed irrelevant to my enquiry, that's because they have remained unproven.
"I find it entirely irrelevant and I make it clear that it will not form part of my enquiry."
-> Killer to be sentenced over fatal stabbing in Sheffield streetHe added: "He said it was a secret but he had already shared it with a friend. It was something important to him."
DS Moorhouse told the court: "A Snapchat exchange was brought to our attention, it would have brought criminal charges.
"A decision was taken that an arrest was the best thing to do. Kit was released under investigation. He was not charged."
Giving evidence, Kit's mother Jill Mangles, said her son had been suspended from Ampleforth College days before his death after teachers caught him smoking on school grounds for a third time.
Mrs Mangles then received a call from a school official on June 14, who told her Kit was being suspended from school indefinitely because the police investigation into his alleged crime was ongoing.
Mrs Mangles relayed the information to her son but told him they would talk about it properly that evening after her husband, his dad, Edward returned from Hong Kong, where he works as a consultant.
At around 5.30pm she left the house to collect her husband from York train station, leaving Kit alone on the sofa watching television.
When the couple returned and found Kit had left in his car, they notified police, his school and friends that he was missing.
-> Two men arrested over trying to kidnap girls 10 and 12 released without charge The court heard the teenager had accessed his father's locked gun cabinet before leaving the property.
Officers found the boy's Skoda Fabia parked at Blakey Ridge at around 10.20pm and discovered his body close by not long after. He was pronounced dead at the scene.
Mrs Mangles described her son, who was born in Hong Kong and left for Ampleforth College when he was in year six, as a "happy" and "popular" boy who "lacked confidence".
She added: "Kit was a happy, popular boy with lots of friends. He was naughty but naughty is as far as it ever went.
"He was very cheeky, when we went to parent teacher meeting they would say 'I love Kit but...'
"I never had any concerns about his mental health."
Mrs Mangles added he had begun the admission process to join the army and was due to attend a three day interview one week after his death.
An autopsy found Christian died as a result of a gun shot wound to the head.
The verdict of the inquest found his cause of death was suicide.