I have seldom heard of such a silly idea, but it comes up now and again. Once again, it's a way of blaming women for problems instead of the men who actually cause the problems. According to the BBC Reality Check, in places where it has been tried it has little effect, and the danger is still there when you arrive at the station and get off the train.
How they think ScotRail can provide enough carriages for a start is one question, as there are a lot of 2-coach trains and it would mean almost half the population, plus mixed parties, crowding into half a train.
As Doodledog says, women can be violent and unpleasant too, so a women-only carriage wouldn't help.
Any male who fancied his chances of a bit of sexual assault would just have to claim to identify as a woman anyway (also mentioned in the OP).
Why on earth not spend a lot less money in employing more staff and British Transport Police officers and deal with the offenders properly instead of making women, once again, hide away and alter their behaviour because of some (and by no means all) men?