Between the age of 4 and 7, DD had to deal with 3 DGGPs (i.e. 3 of MY DGPs) dying. In the first case, I attended the house where the open coffin was alone, and DH brought DD to the church for the removal ceremony, where I met them. She went to her normal creche the day of the funeral instead (and really enjoyed it as, due to summer holidays, there happened to be an outing to a major sports stadium that she was able to go on).
For the latter 2, it was trickier. She needed to come to both houses due to DH work commitments (the 1st, he had a meeting he couldn't get out of, the 2nd, he was the other side of the globe). But we had talked to her beforehand about the death anyway (all 3 were relatively expected), and I found out from others which room the coffin would be in beforehand also. So I was able to explain it to her and give her the choice.
In the first, she stayed outside the room entirely.
In the 2nd, she pretty much stayed outside, but there were other DCousins her age who were going in and out so she did go inside the door for a moment at one point (but was too short to see into the coffin - I offered to lift her but she didn't want that).
For all 3, she only went to the Church for removals the night before, and not to the funeral mass and burial/cremation nor to the wake/meal afterwards. DH came with me to the first 2, but couldn't get home from the other side of the globe for the 3rd.
Even when it came to her DGF, when she was 9, she didn't want to see him in the coffin despite younger DCousins being in and out all day long. But she attended all the ceremonies, and the gathering afterwards (much larger but less formal, soup/sandwiches event - not full sit-down meal).
I looked at the Winstons Wish website for advice, and it was great to be able to talk to DD, and also to other family around about NOT pushing DD to do something she was not comfortable doing.
It gave her the option to go in, but it was HER choice. I didn't want to either scare or upset her, particularly as DH was away so much at that time (he spent 2 consecutive weeks every month the other side of the world) so it would have been me dealing with the fallout, on top of the fallout for me of just losing my DGP.
DD was very close to all 3 and saw them regularly - even up to the day before they died in 2 instances. And the same with DFIL, her DGF, he had a very short time after cancer dx, and DD saw him a number of times (we spent a lot of time "down home" in that 6 weeks) in hospital and hospice, just did not want to see his body.
I was 19 when I saw my first body, my DGF, and I was terrified (no one had explained much about being so cold and he didn't look like himself as they left out his dentures).
Talk, at home, gently but clearly (Winston's Wish gives good advice on language), to he knows what has happened and also that he has a choice. That choice can be made at home before you ever go anywhere, or it can be left open to decide at the funeral home or where DGM is laid out.
And once HE has made the decision, that is it. Don't let others in the family badger you into bringing him in if he has decided he doesn't want to - I stood in the doorway for prayers with DD holding my hand but standing in the hallway for 1, for example - she needed my touch, I needed to be in the room, and that kept everyone happy. And equally, if he has decided that he wants to see her, let it happen and tell the other family members that this is his decision and it is not upsetting you or him to do this (as they may be upset letting him do that). (And give DS the chance to talk about it later - let him know beforehand that it might not be a good idea to talk about it straight away, but that you will be able to talk in the car or at home if he has any questions, and then make that time/space for him to ask in a safe space - just so that his innocence in asking doesn't offend anyone outside your nuclear family, and possibly even just you and he if it is DMIL, or DH and he if it is your DM - so his questions don't unduly upset the person directly bereaved).
People get funny about death, and how things "should be done" - often without thinking about the impact of those things or their words on others. But everyone needs to understand it happens and how to deal with it.