It utterly depends on the funeral, the relationship, whether other close to the deceased mourners will be pleased/ upset or won't care...
When my husband's grandmother died in her 90s her only surviving child - FIL - wanted all his grandchildren/ her great grandchildren there. The kids did know her but were only 8, 6 and 3. We took them to the whole thing - service, grraveside and wake - the 6 and 8 year olds behaved completely appropriately and FIL wanted them to scatter soil on the urn, which was buried, and which they did with FIL, DH and their uncles - they were somber at the service but not upset as we'd talked about it in advance and although she'd been in good health until only about six months before her death, those last six months were clearly the end and everyone was prepared, plus she was very elderly. All the children were mentioned by name several times during the service - they mattered to their great grandmother even though she only saw them around three times per year due to distance.
I had to take the three year old out of the service as he started singing 'The Wheels on The Bus' loudly during the first hymn, but fortunately given the context this made people smile - still I took him out straight away. At the graveside he was quiet until the officiant mentioned saying our last goodbye, when he unexpectedly blew a loud kiss and waved it towards the grave - again in the context people were indulgent and said she would have loved to know he did that. At a different type of funeral it would have been mortifying but it's still reflected on fondly now (which is embarrassing as he's a teenager!).
All the children attended their grandmother's funeral too at ages 5, 8 and 10 - that was a much more upsetting funeral as she died quickly and unexpectedly in her 60s, but again the key people wanted them there, she'd longed to be a grandmother and tried so hard to live to see our youngest start school (at 6 wherecwe live) and not made it - there was no question of them not being there. The youngest was able to behave impeccably for the duration of the funeral at 5 and all of them completely understood what was happening.
So I'd say 5 tbh and younger if it's appropriate to the context of mourners and type of funeral and relationship.
There's a good reason for rituals like funerals as a part of processing death and honouring the deceased and I'd say it's often helpful to children and wanted by the deceased and other mourners, but obviously to be decided sensitively on an individual basis.