Section 117 responsibility when patient changes GP in hospital

Continuing the discussion from ICB commissioning responsibility for detained patients:

I have only just joined and still unsure how or where to ask questions but this post is pertinent to the question I wish to ask if someone can help please. Person is detained under s2 MHA whilst registered with GP A, whilst on S2 changes to GP B and then S 2 converts to S3, which ICB is responsible commissioner for S117 on discharge, GP area A or B? Thank you