The expression “loose cannon” or “loose cannon on rolling deck” refers to an irresponsible and reckless individual whose behaviour (either intended or unintended) endangers the group he or she belongs to, or just generally winds them up with their wrong-headed logic.
The term originates in the Age of Sail and wooden men-of-war, apparently first used in Victor Hugo’s’s novel Ninety Three in 1874. When a storm began, all Cannon had to be securely fastened and lashed in place. A gun that broke free of its lashings would roll uncontrollably around the deck with the motion of the ship, causing havoc. A loose cannon, weighing thousands of pounds, would crush anything and anyone in its path, and possibly even break a hole in the hull, thus endangering the seaworthiness of the whole ship. If a loose cannon fired in the wrong direction, it could severely damage the ship or kill crew members.
In modern usage, it is used almost exclusively to refer to individuals with largely uncontrollable and thus potentially destructive behavior, but it can also be proudly self-descriptive.