I suggest you read the article on “
Apocrypha” in the Catholic Encyclopedia, especially the paragraph on “Apocryphal Gospels” and the following paragraph on “The Protoevangelium Jacobi, or Infancy Gospel of James” in the section on “Apocryphal gospels of Catholic origin.”
Basically, it is a pious fiction ascribed to the second century and written by some overzealous Catholic. Most of the details were made up and so it is of no historical value but it does help us better understand the religious conditions of that time; it is indicative of the veneration paid to Mary at that time.