'Brig' was originally an abbreviation for 'brigantine', a type of two-masted sailing-ship. By the mid 19th century, it had taken on the slang meaning of an onboard prison in the US Navy. It first appeared in print in a publication called 'Knickerbocker' in 1852.