My DS has done this too and it did pass after a couple of weeks. Unfortunately, it's hard work for a bit while they go through it. It's a development stage and for me, it's happened a couple of times. DS is the same with DH, he doesn't want him when he's upset, he only wants his mummy.
One thing that was suggested to me and seemed to work, is to tell him bye bye and I'll be back soon when I left the room and said hello when I came back. I think he began to understand, even when I was only leaving the room for a short period.
I'm sorry I couldn't offer much, but I hope he gets over it soon. Best of luck