Pre- Troll Hermione just all around makes more sense if she's black.
Now, I admit, I don't know a lot about British Black culture, but I know a ridiculous amount about American black culture. I do not think it'd be wrong to believe that at least some aspects would be similar, though if it comforts anyone who knows Black British history and culture, you can just assume that I'm assuming she is actually an American Black who moved to Britian shortly before receiving her letter.
To preface further, I have always struggled with the simple idea that after fighting the troll Hermione simply became friends with Harry and Ron. I have always wanted to know more about Hermione during that time besides she's just a rule following, know-it-all. I find thinking of Hermione with a similar history to Black Americans makes the transition a bit smoother. So:
1. The rule following makes sense if she's black. She has probably been raised to feel that she can have everything taken due to the color of her skin (it's a bit more complex in reality, but I'm not trying to write a full book right this second). She's used to harsher punishments. She's used to things being pinned on her even when she had no involvement. Her skin put a target on her, so she had to play it all very carefully.
2. Hermione is smart. Really smart for her age and period. She may have internalized following the rules but consciously she would be infuriated that these boys would keep flaunting them. If we then head canon Harry as a POC (I like some middle eastern heritage myself), then we can see Harry's attitude to rules as the other possible outcome for a POC, which is an utter distrust of authority figures and a general belief that you have to fight your own battles if you want something to be done. Hermione however would see this little boy of color and be worried internally but externalize it with anger and shaming, because that likely was how she had elders condition her.
3. Hermione would have dealt with bias leading up, she probably thought the Wizarding World was exempt as no one looked at her and acted differently. No, in the wizarding world, the burn would probably be slower for muggle borns to realize the prejudice. Some of them might get unlucky early on, but most of them probably don't encounter it first hand until Hogwarts. Then it's a luck of the draw to what house they are in and who they have classes with. She had learned prior to the wizarding world to use her intelligence as armor. People didn't judge a smart black girl as harshly. Even if she was a know it all, better that then to be judged for being too black. However, the wizarding worlds prejudices are more complicated. Intelligence protects against a lot of muggle born bias (although "for a muggle born" still gets added on to most compliments), but in a house like Gryffindor, where many blood traitors and half blood reside, that same behavior would only turn the impulsive Gryffindors against you. So what was armor would have turned into her own crucifix in the house that valued bravery over intellect.
4. Hermione would have a hard time figuring out why people hated her. She wouldn't analyze every interaction. Now, was it a question of blood, race, or abrasive attitudes. The last would be the hardest to self reflect on.
5. What Ron said was not actually that extreme, not to warrant a hideaway in a bathroom, unless you believe Hermione had been trying for awhile to make friends in the way she knew how to in the racist muggleworld. Those same techniques backfired on her. She would have gone into the wizarding world expecting a new chance, and Ron's statement only reinforced that, if anything, it was worse here then in the muggle world.
6. The troll attack would have clicked some things into place for Hermione.
First, she would have been struggling to figure out how Harry had gotten away with so much. Not consciously, but subconsciously, it would take staring into the professors with a troll behind her for it to click that she would not be judged harshly here (with these individuals) for her race. Rather, there was another metric they measured trouble on, and it seemed to be one largely of whether you were successful and had achieved justice. She didn't know in that moment why Harry and Ron had come, she didn't even know if they had known she was away from the table (I actually suspect she thought they had done exactly what she lies and said she had done, minus the reading part). So she made a calculated risk, thinking this would be judged heroic enough to save the lot of them from the worst punishments (later when she is caught out after sending Norbert out, she cannot find the same feeling of heroism so she reverts to her old habits).
Second, even if she didn't know why Harry and Ron had turned up, the simple matter is they came to save her. Having been bullied and harassed by adults and children alike for her race growing up, watching friends and supposed allies stand by as it happened, them running to help her mattered. I think if they had immediately said something to save themselves or indicate in any way they were doing this simply for glory, she would have never been friends after the troll incident. However, they stumbled and hesitated, and something told her they were trying to save her, not gain glory for fighting a troll.
Third, Ron was teachable if he could get that stupid spell down. Sure, he was insufferable and riffed on her all the time, but Hermione would value a friend who didn't allow any harm to come to her or anyone else to talk shit about her. She could shape him eventually.