Why it was done like that, I'm not sure, but I suspect it was a combination of Scotland having its own legal system and laws (guaranteed by the Acts of Union of 1707) and existing ministerial division of responsibility (where public health in Scotland fell within the purview of the Scottish Secretary, along with Scottish education and a bunch of other areas that had their own distinct Cabinet ministers for England and Wales).
And while the Welsh NHS was originally part of the same NHS as operated in England, control over the NHS in Wales passed from the Health Secretary to the Welsh Secretary with the creation of the Welsh Office in 1969, and then to the devolved Welsh government in 1999.
Northern Ireland already had devolution (or to be precise, home rule) when the NHS was created in 1948, and the Northern Irish equivalent -- the Health and Social Care service -- is a direct creation of the Parliament of Northern Ireland rather than of the UK Parliament.