The idea that some people do not fit into just two sexual or gender categories that are attracted to the opposite one does go back thousands of years, all over the world, and long before science existed.
Why would religions invented thousands of years makes rules restricting behavior that didn’t exist?
I wondered when you used the term "concept" if you were being intentionally vague; and it now appears likely. You get the last word.