Sex is basically defined by what sexual organs you have, basically male or female, and a few people with conditions where it's unclear/they have been encouraged down one route. Sexual organs can be changed to look like other sexual organs, but they won't actually function as those.
Oh nearly there but not quite right. Your biological sex can be observed by your organs but it goes much deeper than that. It’s why women can have blood tests when pregnant to determine the sex of the foetus. Intersex in humans still make you either male or female (if you have the Y chromosome you are male), though it’s true that underdeveloped organs can be an observation issue.
Gender is more complex, in that it takes into account what you identify with - I am pretty sure the complexities of what makes most females feel female and most males feel male isn't completely understood, and thus what would make one feel the opposite gender isn't that well understood either.
This is the crux of the issue - there is no such thing as ‘feeling’ male or female. Only the sociological impacts that are placed on us from birth. Pink and blue, dolls and muck, kind and sweet or rough and tumble. It’s all stereotypes that have built up to the point of ‘if you don’t fit into it, you must be a different gender. These literal visions of being the correct type of girl/boy mixed in with how some people take things very literally (remember how I mentioned how a huge majority of young trans people are autistic?) added in the new age of internet where people can encourage these stereotypes as gender affirming - it’s been a perfect maelstrom.
It's a complex area but undoubtedly people who do feel 'trapped' in the wrong body exist and go through immense heartache coming to terms with it - all I also is that what accept people for who they feel they are.
There is no such thing as a ‘wrong body’, especially when lucky enough to be born healthy. Yes mental health issues are absolutely awful, and no more so than for young people who are autistic or have suffered severe trauma in childhood. It is proven that they often have an absolutely awful time going through puberty and changing bodies. Transgenderism is an escape (especially for girls) but it’s not an actual fix for the MH issues that are never acknowledged with neurodivergence.