It was imposed by Pope Gregory in the 11th. Century. I have heard it was due to two thngs:
1) So the holdings that grew through industry of priests would not be willed to sons and,
2) Royal families were irked that a smart peasant boy might get trained to be a priest, rise through the ranks, and have access to royal circles and then marry into the royal families.
Incorrect.
Suggest you read the following to improve your deficient knowledge of the topic.