Okay, I have dryness, I have keyboard, I have many swirling thoughts that will probably come out a lot less coherently than I'd like.
Gender-as-socialisation within the mind of attacker: yes, I agree with that. The concept of "toxic masculinity" is possibly relevant. Our whole socially constructed system of gender gives out an awful lot of messages about men and women, their roles and purposes, and in the minds of certain types of individuals, in certain circumstances, that translates into just cause for a physical attack.
How the hell that fits in with gender-as-inner-identity, I haven't the foggiest. Does anyone know if there's data detailing the nature of crimes against transwomen? Because if they're, for example, likely to end up raped by the type of individual whose mind is susceptible to our society's toxic ideals of manhood, then we could safely say that it's the gender-as-perceived-by-the-attacker that puts a person at risk. But if they're likely to end up beaten up but not sexually assaulted, then we'd have a good reason to think attackers attack based on biological-sex-as-perceived-by-the-attacker.
I had a lot of trouble writing that paragraph because the true meaning of "gender" in this context is so slippery and elusive. No amount of reading seems to help me to grasp what a gender identity actually is without making reference to either biological sex or femininity in the socially constructed sense. I know I'm not alone in this. I'd hazard a guess that your average sex attacker doesn't have greater insight into gender identity than the rest of us, so I'm pretty damned sure they attack women because women are biologically female. It's got fuck all to do with how those women identify internally.
Socially constructed gender (aka what feminists think "gender" refers to) attributes different traits and propensities to different sexes, entrenching a divide between the two and so creating strife between them. Think of sex as bodies and gender as minds. Minds aren't little isolated bubbles, immune to the tides of society. They're programmed by the society they live in, and they remake society in their turn, in a neverending feedback loop.
Innate gender identity (aka what trans* people think "gender" refers to) doesn't seem to have a great deal of relevance to the fact of sex crimes. Because the perpetrators of sex crimes haven't a clue what gender their targets identify as - they have no way of knowing unless explicitly told by the target - and so are clearly not aiming their attacks at one particular gender identity. We do know perpetrators of sex crimes target women of all ages, sizes, colours, sexualities, women in makeup and women in tracksuits, housebound ninety year olds, and twelve year olds on their way to school. Do all of these females have the same gender identity? I was first raped before I had any idea what a gender identity was, so how could I be said to have had one then?
Gosh, this is getting long. I'm going to disappear for another smoke and hope someone else comes along and posts before I waffle any further.