Just because there is only one likely candidate in the Registers of Baptisms does not mean that he is the right one. Not everyone's baptism record has survived.
John Sommerville and Janet Penman seem to have had at least five recorded children
James, baptised 7 June 1823 in Newton
Isobel, baptised 8 May 1825 in Newton
Richard, baptised 17 December 1826 in Newton
John Penman, baptised 18 April 1829 in Newton
Martha, baptised 21 December 1830 in Inveresk
The 1841 census lists them in Inveresk: John, 64; Janet, 46; James, 18; Isabella, 16; Richard, 14; Martha, 10; Janet, 5.
Looks as if John and Janet may have died before the 1851 census because there is a household in Cockpen, Midlothian consisting of James Somervill, 27, coal miner; Janet, wife, 28; daughters Elizabeth, 3 and Margaret, 11 months, and sister Martha, 21.
There's no evidence that John Sommerville and Janet Penman had a son Thomas or a daughter Margaret, as you would expect if John's parents were Thomas and Margaret.
If John's age in 1841 is accurate, he would have been born in 1776/1777; the schoolmaster's son would have been 67 on the date of the 1841 census.
How likely is it that the son of a schoolmaster and grandson and great-grandson of ministers would have become a coal miner?
PS Was John actually 'of' Miller Hill and 'of' Adamsrow, or was he 'in' Miller Hill and Adamsrow respectively?