If you can put your hand in to any part of that cap and pull out rotted wood,
you have some serious issues. It's hard to tell from that pic, but I assume there is a piece of trim around the edges of that cap, which would have screws under the trim pieces, securing it to the roof and walls.
I'd assume the purpose of it was to give a more "finished" look. Unfortunately if the seams aren't maintained, you get rotted wood.
2014 Itasca Spirit 31K