Locke was born in Attercliffe, near Sheffield in South Yorkshire, moving to the nearby town of Barnsley when he was five. At the age of 18, in 1823, he was apprenticed to George Stephenson and worked on the building of both the Stockton and Darlington and Liverpool and Manchester Railways. In connection with the latter, some reports suggest Locke was driving the steam engine 'Rocket' when Liverpool MP William Huskisson became the first rail fatality on 15 September 1830.
He then graduated from being resident engineer to become chief engineer on the Grand Junction Railway connecting Birmingham and the Liverpool and Manchester line at Newton junction, via Wolverhampton, Stafford, Crewe (much of this railway town was planned by Locke) and Warrington. The stretch across Cheshire included major viaducts across the River Weaver at Vale Royal and Dutton. The railway, sometimes described as the world’s first long-distance railway, opened on 4 July 1837. George Stephenson was initially involved with the scheme but left it in Locke’s hands from 1834 through to completion.
Locke was subsequently appointed to design a railway line from Manchester to Sheffield, a project which included the three-mile Woodhead Tunnel, opened on 23 December 1845. Further north, he also designed the Lancaster and Preston Junction Railway, the Lancaster and Carlisle Railway, and the Caledonian Railway from Carlisle to Glasgow in Scotland.
His rail commissions also extended into southern England. He worked on the London and Southampton Railway, later called the London and South Western Railway, designing, among other structures, the Richmond Railway Bridge (1848, since replaced), and Barnes Bridge (1849), both across the River Thames, tunnels at Micheldever, and the 12-arch Quay Street Railway Viaduct and the 16-arch Cams Hill Railway Viaduct, both in Fareham (1848).
His involvement with railways caused him to become closely acquainted with both Robert Stephenson and Isambard Kingdom Brunel, and both were active in the Institution of Civil Engineers of which Locke became President in 1857, shortly before his death in 1860.
Locke also served as a Member of Parliament for Honiton in Somerset.
Locke Park in Barnsley was dedicated to his memory by his wife Phoebe in 1862. It features a statue of Locke plus a folly, 'Locke Tower'.