This is a great question. I understand how you feel because, at first glance, this mandate looks really harsh - to force a girl who was raped to be with her rapist the rest of her life. And you're correct - in our society today, a girl marrying her rapist definitely would not be encouraged for obvious reasons. Here's how one Biblical reference explains Deuteronomy 22:23, 24:
*“In case a man finds a girl, a virgin who has not been engaged, and he actually seizes her and lies down with her, and they have been found out, the man who lay down with her must also give the girl’s father fifty silver shekels, and she will become his wife due to the fact that he humiliated her. He will not be allowed to divorce her all his days.”—Deuteronomy 22:28, 29.
This was a case of pressured seduction and/or fornication. If an unscrupulous man felt at liberty to have sex relations with a virgin, she would be the primary loser. Besides the possibility that she might have an illegitimate child, her value as a bride was diminished, for many Israelites might not want to marry her once she was no longer a virgin. What, though, would discourage a man from taking liberties with a virgin? God’s “holy and righteous and good” Law would.—Romans 7:12.
The Mosaic code had a provision allowing a man to divorce his wife for certain reasons. (Deuteronomy 22:13-19; 24:1; Matthew 19:7, 8) But what we read at Exodus 22:16, 17 and Deuteronomy 22:28, 29 shows that the option of divorce disappeared after premarital fornication. This, then, might cause a man (or a virgin woman) to resist a temptation to share in fornication. A man could not feel, ‘She is pretty and exciting, so I’ll have a good time with her even though she is not the sort I’d like to marry.’ Rather, this law would deter immorality by causing any would-be offender to weigh the long-term consequences of fornication—having to stay with the other party throughout his life.
The Law also lessened the problem of illegitimacy. God decreed: “No illegitimate son may come into the congregation of Jehovah.” (Deuteronomy 23:2) So if a man who seduced a virgin had to marry her, their fornication would not result in an illegitimate offspring among the Israelites."
So, then, Jehovah God - whose thoughts are higher than ours as humans - had a very good reason for establishing the command found in Deuteronomy 22:28, 29 - that of protecting the violated woman and making the rapist pay for his actions. Today, this is not required of Christians, but the principle of that scripture still applies. The quoted reference work explains:
*"Granted, Christians live in a social setting that is different from that of the ancient Israelites. We are not under the decrees of the Mosaic Law, including this law requiring the marriage of two persons who engaged in such fornication. Nonetheless, we cannot feel that engaging in premarital fornication is an insignificant thing. Christians should give serious thought to long-term consequences, even as this law moved the Israelites to do so.
Seducing an unmarried person ruins that one’s right to enter a Christian marriage as a clean virgin (male or female). Premarital fornication also affects the rights of any person who might become the individual’s mate, namely, that individual’s right to marry a chaste Christian. Most of all, fornication must be avoided because God says that it is wrong; it is a sin. The apostle aptly wrote: “This is what God wills, the sanctifying of you, that you abstain from fornication.”—1 Thessalonians 4:3-6; Hebrews 13:4.
I hope this information is helpful to you.