The 17-year old Dunedin male had gone to court to make a bail variation application. When court security staff asked him what was in his bag, he volunteered he had the BB gun inside.
Security staff handcuffed the youth, took him to a room for questioning, and police were called.
Southern District Command Centre Senior Sergeant Ian Temple said it was not an offence to carry such a gun, the teenager had volunteered the information to security staff, and he was not behaving in an unlawful manner.
"He wasn't doing anything wrong but it's not appropriate to take a BB gun into a court, so it was removed."
The youth was spoken to by police and court staff and was released.