The view I was taught was that it was regarded as a way to strengthen ties among the soldiers, so they would fight their absolute hardest.
Euboulos (cited by Athenaios in Deipnosophistai
1, 46) had a different version - according to him, it all started as a bitter necessity during the long decade of the siege of Troy:
ἀλλ' οὐδὲ μίαν ἀλλ' ἑταίραν εἶδέ τις
αὐτῶν, ἑαυτοὺς δ' ἔδεφον ἐνιαυτοὺς δέκα.
πικρὰν στρατείαν δ' εἶδον, οἵτινες πόλιν
μίαν λαβόντες εὐρυπρωκτότεροι πολὺ
τῆς πόλεος ἀπεχώρησαν ἧς εἷλον τότε.
"No one ever set eyes on a single hetaira [prostitute];
they wanked them-selves for ten years.
It was a poor sort of campaign: for the capture of one city,
they went home with arses much wider
than (the gates of) the city that they took."