The earliest written reference to celibacy comes from 305AD at the Spanish Council of Elvira, a local assembly of clergymen who met to discuss matters pertaining to the church. Canon 33 forbids clerics in the churchbishops, priests and deaconsfrom having sexual relations with their wives and from having children, though not from entering into marriage. It was not until ecumenical meetings of the Catholic Church at the First and Second Lateran councils in 1123 and 1139 that priests were explicitly forbidden from marrying.
Eliminating the prospect of marriage had the added benefit of ensuring that children or wives of priests did not make claims on property acquired throughout a priests life, which thus could be retained by the church.
It took centuries for the practice of celibacy to become widespread, but it eventually became the norm in the Western Catholic church.
https://www.economist.com/the-economist-explains/2017/03/23/why-catholic-priests-practise-celibacy