Unfortunately, I've been to more than a few funerals since I had my first kid, and she's been to quite a few. My second is only 19 months, but he's already been to one grandpa's funeral. They stayed the whole time and played with their older cousins. My father in law was in a nursing home for a long time and had alzhiemers, so when he went, it was a blessing for the family, and was a long over due opportunity to commemorate his life and enjoy the large blended family that resulted in this being his and my mother in law's 2nd marriage. The funerals my 5 year old has been to were a chance for her to learn about death in a natural way with family around, so she can see that it's a part of life and life still keeps going for the family even after we say goodbye to someone.
For your son, this will be a significant milestone that will illustrate the concept of life and death. It could be very rewarding and positive for your son, but it may be a time of unease for him that you'll need to guide him through. He might feel scared and ask questions about who dies and why, but this is a teachable moment that will answer a lot of questions all at once. And it gives people who are mourning a sense of hope and eternal love to see children, it really does heal and bring smiles to the most broken faces. Recognizing someone passing on is a community experience. It's a time for togetherness and comfort, and that includes all members of a community.
Another concept that can aide in reassuring little ones is that every day there are new babies being born, just as there are elders dying.
Also, most funeral homes have a room for children to play or adults to talk, so if there's a rotation of adults or older kids there to supervise, you could have him spend most of the time in there. have him pack a backpack with coloring books and small toys so he has something familiar that he can do.
As for the baby, she will just think of it as another family gathering, and it will bring joy to the occasion that is welcomed especially when older folks die that we were ready to say goodbye to. It's another thing to consider when it's a tragic loss like a child, or young parent. That would be pretty scary for a little one, as it would be intensely emotional and harder for them to understand.
But the key is, to present death as something that we have to accept in life and that it's okay for everyone to feel sad for a while and everyone always feels better in the end.
Good luck with this important subject between you and your son, and hopefully this won't have to happen soon. I wish your loved one a peaceful ending to her life, and hope that your family will find comfort in the end of her suffering, as she passes on.