Psalm 139 is the most specific passage in Scripture about God's knowledge of human life before birth. "Thou hast possessed my reins: thou hast covered me in my mother's womb." The word "possessed" — qānāh in Hebrew — means to acquire, to have ownership of, to form as one's own. God's claim on a life is described as beginning before birth, in the womb, in the hidden place. Verse 16 adds: "thine eyes did see my substance, yet being unperfect; and in thy book all my members were written, which in continuance were fashioned." Your child was seen. Was written in a book. Was known.
The question of why God allows miscarriage has no satisfying answer that Scripture offers, and it is worth being direct about that. The book of Job is the Bible's most extended engagement with innocent suffering, and God's answer to Job at the end is not an explanation — it is presence. God's response to Job's suffering is himself, not a theodicy. That is the honest shape of what the Bible offers to this specific grief.
Jesus's language about children is worth sitting with. When the disciples tried to send children away, he said "Suffer the little children to come unto me, and forbid them not: for of such is the kingdom of God." He did not attach conditions of age or development to that belonging. The kingdom is described as belonging to those who are as children — and your child, however briefly they existed, existed fully enough to be known by the God who made them.
Commentary is from a charismatic Protestant perspective, drawing on KJV text and public-domain sources including Spurgeon, Andrew Murray, and Matthew Henry.