A Few Things To Keep In Mind:
The Platinum Rule: Treat the hurt how they want to be treated.
Say their baby's name. It means the world to the parents to hear it from someone else.
Be cautious of triggers: don't bring up future children unless you are certain the person is okay with that conversation.
Less is usually more when it comes to words. But also cards in the mail and random text messages mean a lot (I know a lot of bereaved parents that kept the cards they received for decades).
Actions speak louder than words (see the post about practical things you can do for a family for action ideas).
If you are tempted to share your story, make sure it is about you. Make it a "me too" moment, not a "my grandma had a miscarriage, too" or "I have a friend who lost a baby, do you want to meet her?". Bereaved parents are now part of a club they never wanted to be in, so an invitation to feel a gentle welcome to that club should feel like a warm embrace.
Examples of What You Can Say
"I'm so sorry for your loss" or "My condolences" (this is the most basic thing you can say. It's not super effective at showing empathy, but it is better than nothing)
"I absolutely hate that you are going through this."
"Hey, can I bring dinner over to you guys tomorrow? You are still constantly on our hearts."
"I've been thinking of you and praying for you. Is there a way I can help you guys?" or "Is there anything I can do for you today, right now?"
"You are their mama, and you love your baby so so so much. You are an amazing mom."
"We are here to support you, for whatever that entails. Just call and we will drop everything to be with you." or "If you want to just sit together, or talk, you have my number."
"You gave them the absolute sweetest name. A precious name for a precious baby."
Examples of What You Shouldn't Say
Nothing. Don't say nothing (in my personal opinion as a loss mom). See the list above for at least something to say.
"At least you have another child" or "At least you can have another baby" (anything that starts with "At least")
"God doesn't give us more than we can handle" (this phrase is actually referencing temptation and sin, which has nothing to do with death)
"God doesn't make mistakes" or "It must have been in God's plan" (We can all agree that God doesn't kill babies so let's just not say this)
"When are you going back to work?"
"Would you just get over this already?" or "Come on, it was just a miscarriage."
"I can't imagine what you're going through."
"You should be taking care of your other kids, not this."
"You look like you are doing great! I'm so glad you're over this." or "You must be over the grieving, because you look fantastic."
"Hey, if you're not gonna use that crib can my sister have it?"
You might be surprised at how harsh those "don't say" items are. They are nasty and cruel. And they shouldn't be said to a grieving mother or father. But every single one of those phrases has been said to either myself or a friend who lost their child. I had to look into the tear-studded eyes of a mother as she retold that encounter. I didn't find this list off of the internet.
If any one of these things has ever been said to you I am so, so sorry. You don't deserve that. Don't be afraid to set boundaries if someone continues to treat you this way. State how hurtful it is, and move on. Being bullied for losing a child is real, as crazy as that may sound. We live in a world with some very unempathetic people and it can be very difficult to live in that society. This is where I would also encourage moms and dads who have lost a child to take a very hard look at their social media usage, friends, and any incoming material and evaluate whether it is healthy or harming.