It was a gift from God.  I think basically the reasoning was that the
tradition in the Church held that Mary was also without sin as was Jesus.
As the tenets of faith developed, particularly with Augustine, sin was
more and more equated with sex, and thus Mary was assumed to be a virgin
for life (since she never sinned, and since she was the spouse of God, etc.)
Since we also had this notion of original sin, ie. that man is born with
a predisposition to sin, and since Mary did not have this predisposition
because she did not ever sin, she didn't have original sin.  When science
discovered the process of conception, the next step was to assume that
Mary was conceived without original sin, the Immaculate Conception.

Mary at that time appeared to a girl named Bernadette at Lourdes.  She 
refered to herself as the Immaculate Conception.  Since a nine year old 
would have no way of knowing about the doctrine, the apparition was deemed
to be true and it sealed the case for the doctrine.

RCs hold that all revelation comes from two equally important sources, that
being Sacred Scripture and Holy Tradition.  In this case, mostly tradition.