It means "It could not avoid affecting him." "It could not do anything else but affect him. "It had to affect him." "It affected him; it was impossible that it could not."
"Could not but" is a colocation. It's a little literary and old-fashioned.
I can't really explain why it means what it means!
Here are some examples of use.
"I didn't know the best way to learn Spanish, but I was sure that setting my computer to use Spanish could not but help."
"The poor unhappy gentleman’s grief came into my head again, and indeed I could not but shed tears in the reflection upon it." (Daniel Defoe, 1772) It was so sad that he couldn't resist crying.
"it was a degree of wilful thoughtlessness which Catherine could not but resent."--Jane Austen, "Northanger Abbey," 1812. It was too thoughtless. It was so thoughtless she couldn't possibly forgive it. She had to feel resentful.