The simplest answer is to segregate by sex, it's not clear why gender identity should require moving to another facility.
Regarding the supposed issue of safety of trans identifying male prisoners in male prisons (I haven't seen data around this but let's assume it's an issue), it's still not clear the answer is housing with women. If a gay man is more likely to be abused in a male prison, or a small or young man, does that mean men with any of these characteristics should be put in women's prison to improve their safety conditions? This doesn't scan.
Its notable to me that as concerned as you are about prisoner safety, I don't see you or other advocates of males in womens prisons mention the safety of the female prisoners should men be added to their cells. Does their safety not rate?