What you do is just tell them the truth -
"Wow you lost a lot of weight! You look good!"
"Yeah, I'm actually recovering from an illness. I lost nearly a 5th of my entire body weight."
And then let them hang in silence or say whatever bs they want to back-peddle with like "oh nooo are you okay...???" and then you can tell them:
"yeah it's been interesting, a lot of people have been commenting that I look so much better even though losing all that weight brought my BMI dangerously low and nearly put me in the hospital. It's been an interesting ride."
They are the ones who brought it up, they are the ones who put you in this uncomfortable position in the first place, they are the ones being rude. There is nothing rude about you simply telling them the truth of the topic that THEY chose to bring up. A topic that is frankly none of their damn business. If they happen to realize that the situation they created is uncomfortable then good for them.
Commenting on other people's weight is always inappropriate and unnecessary, regardless of whether it is a "nice" comment or a mean one. The only time it would fine is if it's your parents or your partner and you notice a change in weight up or down and you are therefore looking to ask after their well-being. People love to make comments about other people's appearance and weight in the name of "health" but the fact of the matter is that other people's health is none of their damn business. Beside that, you can't look at someone's outside and make a conclusion about what's going on inside. Skinny people can be unhealthy and out of shape, fat people can be strong and healthy. For the sake of not risking an offense you'd think people would just learn to leave out unnecessary comments.