Based on the case you present, the girl was raped by a boy in a hotel. That is the correct descriptive statement.
As you note, when this is delivered in reported speech, a conversion takes place, as follows.
Direct Speech: The girl said, "I was raped in a hotel."
Reported Spch: The girl said that she had been raped in a hotel.
Alleged/said, same principle, these are just reporting verbs. Therefore, the correct sentence from your question is:
- A 21 year old girl studying in Vidynagar alleged that she had been raped by a boy in a hotel in the city on August 23. Based on
above complaint police arrested the accused. (edited for
I'm not sure if this answers the "why" part of your question, or if you are actually asking why we do this for converted speech.
If the latter, then the reason we do this for reported speech is because there are three events on the timeline:
A: when the event happened (the rape)
B: when the speech happened (the girl describing her experience)
C: when the report happened (a third party repeating what the girl said)
Since A happened before B, then at time C, we refer to it using Past Perfect.