Your William Hartley may well be innocent.
In 1851 there is a 19 year old William Hartley, born Lanarkshire, in jail in Glasgow.
In 1858 (27th April) William Hartley, labourer, Saltmarket, Glasgow, was tried for theft, habit and repute, and previous conviction at the High Court in Glasgow. The sentence was 5 years penal servitude.
In 1863 (22nd December) William Hartley, 33, labourer, 78 Saltmarket Street, Glasgow, a native of Glasgow, was tried for theft, habit and repute, and previous conviction at the Hight Court in Glasgow. The sentence was 7 years penal servitude.
In 1873 (23rd April) another William Hartley, 44, Uddingston, Bothwell, a native of Berwick on Tweed, was tried for bigamy at the High Court in Glasgow. The sentence was 12 months imprisonment.
In 1879 (23rd December) another William Hartley, 14, 9 Lyon Street, Partick, Glasgow, was tried for theft by housebreaking and previous conviction at the High Court in Glasgow. The sentence was 5 years penal servitude.
The first three Williams above look as though they are the same person. The sentences would rule him out from being your man. A terrible lot these Hartleys all the same

.