I have a friend who studies this stuff and is somewhat of an expert, so while I risk misrepresenting her summary version about the impacts of weight on health it's something like this:
1) Being merely overweight isn't really correlated with negative health outcomes or increased mortality.
2) Being highly obese isn't really correlated with increased mortality, though it is correlated with negative health outcomes (diabetes, heart disease, etc.).
3) The reasons that obesity is correlated with negative health outcomes but not increased mortality are: a) better modern treatments of those conditions, and b) if you do get seriously ill (like, say, cancer), having extra weight seems to improve your chance of living.
4) On balance it's probably good to never gain too much weight. However, there's basically no evidence that once weight is gained (and again, we're talking about a lot of weight for it to really affect health outcomes), that losing it is actually going to increase your lifespan. If anything, the evidence points in the other direction, that extreme dieting and especially yo-yo dieting (which isn't something anyone recommends, but is common given normal human behavior) actually increases mortality . So don't gain the weight, but once you do, taking it off might not help. Yes there are certain conditions that can be improved by weight loss, but weight loss might actually increase your chances of dying. Might help your knees, but won't necessarily help you live longer.
5) Increasingly the evidence suggests that having a reasonably active lifestyle (not being a complete couch potato) matters much more than the weight itself for the various negative health outcomes that are correlated with weight. Obviously weight itself is correlated with your lifestyle, but the point is that the weight itself is less of an issue.
Anyway, fat-shaming is an aesthetic thing and has only a modest relationship to health concerns, which for some reason only get applied to fat people.