The makeshift weapon had been confiscated in a raid on a property in Leith, Edinburgh, earlier this month.
Three days later, forensic specialists were examining it at Gayfield police station when it went off.
Details of the incident emerged in a report for a meeting of the Scottish Police Authority (SPA).
SPA forensics chief Tom Nelson said: "Two forensic science staff were carrying out an examination of a home-made firearm. During this inspection the weapon was discharged and a projectile was lodged in the wall of the room.No-one was injured."
Investigations have been launched by the Health and Safety Executive and the Police Investigations and Review Commission (PIRC), which is informed of every "unintentional firearms discharge".
A man and a woman appeared at Edinburgh Sheriff Court following the raid, charged in connection with the weapon. The case was continued.