I've been there, OP, and it's hard, so I do appreciate how you feel.
My ex-DP (yes, an ex, but not related to this!) told me that he was avoiding sex because I was overweight. Like you, I'd pestered him and pestered him until he told me the truth. In retrospect, the poor guy couldn't win.
At the time I was devastated. If you'd asked me then, I'd have said "I'm only a size 12, what's he complaining about, and he's not an Adonis himself."
But years later I see it differently. He was telling me the truth. I was unhealthy; I'd piled on almost 3 stone in 2 years, and I'd tipped into the overweight category. I wasn't happy in myself. I looked and felt awful. I was eating badly. I don't blame him for being put off sex, tbh, and in fairness he only admitted that after I asked him time and time again. He was in an impossible situation. He couldn't help how he felt and, after a lot of tears and demands from me, he thought telling the truth was the best option.
Looking back, I wish at the time I'd taken it as a wake-up call to how unhealthy I was becoming. Yes, a size 12 doesn't sound huge, but I was medically overweight and frighteningly unfit. I'd completely normalised my weight, my terrible eating habits and my lack of exercise. So I carried on that way for a few more years until realising I had to change, so I did. I lost the weight and running changed my life, in terms of my mental health just as much as physically. (The relationship had ended by that point, but we're still good friends).
I'm sharing this experience because I think you have the power in terms of where you go from here.
It sounds like you're not happy with your weight, as you say you're trying to lose some. So it's up to you how you choose to deal with the comments from your DP.
You would be entitled to think he's being a dick and to be upset about it. You may even choose to end your relationship over this, as some PPs have suggested.
But equally - if he's ordinarily a good guy - you could choose to take it on the chin and accept that he was only telling you the truth after a long period of badgering.
Give some real thought to what an acceptable response from him would have been. I know it's hard, and it's hurtful, but if you can't answer that question, perhaps you should accept he couldn't win on this one. Good luck 