Women used to be composers in earlier days too, and acknowledged they were as well ... but something happened. Music history is, unfortunately, written by men, and some of them seem to have been chauvinists ... female composers have simply been "forgotten" or "neglected" during the years. Too bad, isn't it?
My teacher is extremely interested in this topic of female composers, and she introduced me to a Norwegian composer named Agatha Bakke-Gröndahl. Heard of her? I bet you have not. Anyway, her music is lovely (and rather difficult as well), and I remarked it sounded very much like Grieg. No wonder, as she was one of his contemporaries, and just as respected as him! By then. Later, history writers have "forgotten" her. Male music professors prefer to deal with male composers instead of female. Just go to a conservatory and ask to study female composers in particular. That request will not be well received!
(This is nothing unique. Back in the old days, the third century after the death of Jesus, the books in the Bible were "edited". Heavily edited. And after that, Jesus had only male disciples, Mary Magdalene was a prostitute, and all the remaining books in the Bible just happened to be written by men ... But before this revision, the truth looked a bit different! )
So, playing the piano and writing music was a fully respected profession among women as well, back in those days. But we also know that there have been times when it was considered plainly "inappropriate" that women were on stage, that men sat quiet and listened and looked at a woman performing something.

Or that men gave a woman credit for being good at something except being a good mother/wife etcetera.
Today, thank God, things have changed, although I, as a writer, have experienced that many male readers refuse to read a book if they realize that it is written by a woman!!! They are not even ashamed of admitting it, even though it is utterly stupid. We all know that female pianists are just as good as men - not better, not worse, the gift just seems to be totally independent of gender. Unfortunately we still have not totally left the dark dungeons of sexism ... a male pianist may look as a horse, he can still be respected for his performance, but a female pianist always get comments about HER LOOKS.
So, obviously there have not been as many female composers throughout history as male composers, but the explanation is HARDLY that "women cannot write music".