It serves at least three purposes (that I can think of...) 1 - It provides some insulation; 2 - it seals up any holes it covers; 3 - it holds things (like wires) more firmly in place.
Of course, it makes it tough to trace wires as they disappear into the foam...
__________________ If "Search this Forum" does not yield answers, please post questions as a "New Thread" (instead of asking privately) so others can benefit from the answers.