This prohibition seems to make little sense. If marriage is good and can be a legitimate part of the clerical state, as it is in the East for priests and deacons, and in the West for permanent deacons, why should there be a law forbidding marriage after ordination?
The answer most coherent with the fact of this universal law is that there was an apostolic discipline of clerical continence (i.e. abstinence from sexual union) even for those who were married, and that the existing law, which applies even where clerical marriage and the use of marriage is retained, is a vestige of the ancient discipline.
This accords with the words of Our Lord:
Jesus said, "Truly, I say to you, there is no one who has left house or brothers or sisters or mother or father or children or lands, for my sake and for the gospel, who will not receive a hundredfold now in this time, houses and brothers and sisters and mothers and children and lands, with persecutions, and in the age to come eternal life. (Mk 10.29-30)Of the apostles, we know that St Peter was married because of the mention of his "mother-in-law" (Lk 4.37-39) and yet we hear nothing about his wife at all.
St Paul says that the bishop must be the husband of "only one wife" (1 Tim 3.2). He is surely not intending here to express a prohibition of polygamy which would have been obviously abhorrent to Christians. Much more likely, he is saying that the Bishop should be a man who, if his wife has died, does not marry again. Why? Because a Bishop is someone who has left "wife and children" for the sake of the kingdom.
The discipline whereby only unmarried men were ordained is an obvious development from this, not an innovation of the middle ages.
For further information, see the article by Ignace de la Potterie at the Vatican website: The biblical foundation of priestly celibacy.