Celibacy is preferred to the married state because married men are very concerned with the world, pleasing their wives and providing for their families. Men with holy orders can to be focused only on God. This dates back to apostolic times. Something like if you do not have a wife, don’t look for one.
Scroll down to the “history” section.
The short answer is: it’s complicated.
It seems almost all agree that that the Middle Ages brought about the solidifying of the tradition that mostly stood already.
This is also interesting…
I hesitate to give the next link because many of their conclusions are … well … COMPLETELY erroneous, however, I find their “facts” intriguing and their timeline to be well formatted… If there are any Catholic history buffs out there, I wonder if these “facts” stand. I recognize enough of them to believe there is some merit in them.
Please try to avoid their exposition as it is purely speculative and asserts itself with authority it simply does not have.