I had a check and it looks like the law was passed in 2012[1]. They say that gave them a legal responsibility to hold clinical information, combined with instruction from government that should be enough for this to fall under another basis in GDPR without consent being required. Not saying it's right, especially with the risk of the data being shared further once they hold it, but it'd probably be difficult to challenge.
[1] https://digital.nhs.uk/about-nhs-digital/our-work/keeping-pa...