It's just the same for transgender people. Growing up feeling that you're in the wrong body can cause a lot of mental distress, and the best and most universally effective option for fixing that distress is to simply transition to living as another gender.
Not all people who are transgender experience severe enough dysphoria to cause serious mental health issues, and yet they still decide to transition and report being happier afterwards. [1] However, many transgender people do experience distress over it, and a proportion of that population are even suicidal over it.
This is why I consider it to be a cause of mental illness, not a mental illness in and of itself. And it's important to note that, even for the group that experience suicidality, transitioning is still an effective treatment. [2] [3]
Plastic surgery, on the other hand, is not even close to universally effective for people who are depressed about being "flat-chested" or "ugly." Cosmetic surgery such as breast enhancement has been shown to have a much, much higher rate of regret than transgender surgeries. [4]
In short, the reason that gender-affirming care is considered a treatment for gender dysphoria, whereas breast enhancement and rhinoplasty are not considered treatments for body dysmorphia, is simply that the former is effective and the latter is not.
1. https://www.apa.org/topics/lgbtq/transgender-people-gender-i...
2. https://pmc.ncbi.nlm.nih.gov/articles/PMC10925986/