I think he could tell the story without saying who shot him. That's presumably what Magnusson did. I don't know how it works, but as they had Magnusson as a seemingly reliable witness, they didn't need Sherlock's testimony so urgently and could wait until he had recovered a little. There was no reason to think that Sherlock would know the attacker, because she was breaking into Magnusson's office and supposedly after him (and shot Sherlock because he surprised her and she needed to escape). I don't think anybody else would suspect Lady Smallwood, as only Magnusson and Sherlock knew she was a possibility.
They could have questioned Sherlock in hospital (up until he escaped, there was Mary's threat, so he wouldn't have told, and afterwards there was the agreement with Mary and John, so he wouldn't have told), either before or after escaping, or after he was discharged.