How do we know that the Protoevangelium of James is credible?
We don’t. But since it is a very old document, dating to about A.D. 150, it gives us an idea of some of the stories that were circulating regarding Mary’s childhood and the selection of Joseph to be her guardian and spouse. It opens our minds to other possibilities, specifically the idea that Joseph was an older widower, not a young man, and married Mary to be her support and protector of her virginity.
You do not have to believe that the Protoevangelium of James is accurate. But it could be, and that gives us new things to ponder.
You can read the Protoevangelium of James here.