It can happen. My dad just got out of six years in a state prison because some girl he had a relationship with 20 years ago got the idea in her head that she could get some money from him and accused him of raping her way back then. She tried to blackmail him saying if he gave her all this money, she'd drop the charges, but we wouldn't give it to her. And in most places, if a female says a male raped her, it doesn't matter if it's true or not, the jury always believes the girl.
It's also why I want to get out of classroom teaching. I know it doesn't happen often, but it's happening more and more that teachers, especially male teachers, get accused of stuff like that whether it's true or not. And having watched my own father's life ruined by it, I'm a bit more paranoid about stuff like that than most people. I don't want to be a male teacher in an elementary classroom and I DEFINITELY don't want any parents to find out I'm transgender because that could start a LOT of ->-bleeped-<- with people thinking I'm some pervert.
Most prisons do segregate prisoners, though. For instance, my dad was a model prisoner who never hurt anyone and so he was put in a cell block with other model prisoners. The idiots who would go around hurting people were all put together, so he wasn't really worried about it.
Don't do anything to get yourself put in prison, but don't kid yourself that just by being a law abiding citizen you won't end up in prison anyway. But most prisons aren't as bad as the big federal scary places you see on TV. Most prisoners just want to serve their time and most prisons segregate those who don't. Most will also segregate you if you think you're in danger from being trans. Also, if you haven't had surgery yet, you'd go to a female prison.