Possibly not the most expressive way to ask the question, so I'll rephrase. When did people get the idea that consent is needed for sex, and that rape is a bad thing?
This may be somewhat at the boundary of history and literature, since the latter is how most morals seem to be transmitted.
The bible, for example, has lots of sex with not very much consent; when women have sex, the implication seems to be that consent is required from their dads/husbands, not the women themselves. The Iliad starts out with Agamemnon and Achilles fighting over girls, presumably without asking what they feel. The only objector to their arrangement comes from the priest Chryses, who doesn't mind rape-slavery as long as it doesn't happen to his daughter. Come to think about it, the entire premise of the Iliad is two men fighting over the same chick without asking her opinion.
On the other hand, twenty years later Penelope is choosing her suitors, which seems to be a minor step forward.
Well, first of all, as you’ve already pointed out, you have to distinguish between history and literature.
The examples from Homer are very problematic for two main reasons.
We don’t know when the Iliad and the Odyssey were first conceived or when they were written down. Disregarding the question whether or not Homer was one person, the story was likely written down around 750 BC. Orally, however, the stories are likely much older. The stories are set in Mycenic times (around 1200 BC), it is therefore very hard to determine if any views on morality stem from the time of writing or performing the works or are meant to be a representation on how people would probably have thought at the time the story was set.
Agamemnon and Achilles fought over Briseis. She was a girl from Troy and captured by Achilles as spoils of war. This meant she would basically be treated as a slave. Slaves would be treated more as things than as human beings and although obviously this now seems highly immoral, having sex with a slave would not need consent in order for it to not be regarded as rape. Penelope is allowed to choose her own suitor because she is not slave (although she is not free to not choose a suitor).
Secondly, this question has to be answered differently for every culture. There was never one time at which all the peoples of the world decided rape was not a good thing.
Something that is very interesting however, is how cultures that, at a specific time in their history, definitely condemn rape, still draw on older stories in which non-consensual sex features as part of a history they are proud of. The Romans, for example, do in Late Republican times believe women have to consent to sex. Still, the story on how the early Roman men invited the Sabines to a feast and due to lack of women, decide to capture the Sabinian girls and force them to have babies with them in order to establish the Roman people, is widely told. It is a strange thought the Romans did not try to remove such a story from their history, which might make you think the value they placed on consensual sex was very different from Western society today.