Nursing and thumb-sucking are both "comforting" actions, maybe he just likes doing both at once! My daughter likes to suck from one breast and touch the other.
Since it hurts though, you don't want to encourage the behaviour. You can keep pulling his hand away and if the message still doesn't get across you can look him in the eye, talk to him and say that he can't do it anymore because it hurts mummy.
If you have to, stop letting him nurse whenever he does it. The important thing is to make him understand that it hurts mummy.
Read more