Actually no.
We apparently all live in Nth Carolina
The point is that ever since people built boys and girls bathrooms, it has always been unacceptable for a boy to go into the girls bathroom, much less locker room. Depending on the exact time, place, and circumstances, a boy in the girls' bathroom (or locker room), would either be beaten to a pulp, subjected to corporal punishment (i.e. in schools), arrested, or some combination of the above. Maybe, if it was too much trouble, they might just be run off the property with the threat of future arrest, i.e. "If you ever show your face around here again I'm calling the cops!"
It has never been legal, ever.
No one ever bothered to make a specific law stating it because everyone knew it was illegal. If prosecution were desired (i.e. if someone decided "beating to a pulp" was inadequate or inappropriate) they might use some sort of "peeping tom" law, or they would stretch some sort of disturbing the peace or trespassing law to fit the circumstances. One thing is for certain. Nowhere in the United States would anyone have put up with it, and I am pretty sure the same would be true in all of the English speaking world, and pretty much everywhere else, too.
In 2015, faced with transgender males (i.e. transwomen) using women's private areas, the state of North Carolina said they didn't like that, and they actually wrote it into law for government owned buildings. Why did they do that? To codify the law that had always existed, but it never occurred to anyone that there was some need to write it down.
The laughable part is the claim that somehow North Carolina was introducing some brand new thing that had never been done before. No. They were making sure things stayed as they had always been until very recently.
Whether it is a good idea or a bad idea to do what North Carolina did is a secondary issue. The point is that good idea or bad idea, it was not a new idea.