Originally built to hold prisoners being tried by the Marshalsea Court and the Court of the King's Bench. Its first site, from at least 1329 was on Borough High Street on the block now bordered by Newcomen Street and Mermaid Court. The Marshalsea only became exclusively a debtors' prison in the mid 17th century. Never a model of cleanliness and godliness it was condemned in about 1800 and a new building was constructed on the site of the White Lion Prison (also called the Borough Jail or County Prison), at Angel Place where it was, for a time at least, alongside the King's Bench Prison. British History has the best map we have found showing the locations. The amount of land used by the second Marshalsea varied but at one time it was on either side of the alley. The two sides were very different, known as master-side and common-side, one was relatively clean and agreeable, the other was filthy and inhumane.
On this second site it served its function from 1811 until 1842 when the prisoners were transferred to the new Queen's Prison (a few streets away to the south-west) or, if considered mad, to Bedlam. Most of the buildings were demolished in 1849. In 1824 Charles Dickens' father was, for 12 weeks, one of the debtors imprisoned here. Consequently Marshalsea figures prominently in the Dickens novel Little Dorrit. Dickens remembered "In every respect indeed but elbow room the whole family lived more comfortably in prison than they had done for a long time out of it." Ian Visits has a good post about the Marshalsea.
This area of London certainly attracted prisons, presumably for the same reason that it, at one time, attracted theatres, bearpits and whorehouses - its "Goldilocks" proximity to the City, and it being outside the jurisdiction of both the Cities of London and Westminster.