I must confess to having used foam ONCE to secure an existing box. In that case, water leaking from the shower on the opposite side of the brick wall had resulted in the masonry being too 'crumbly' to accept any anchors, and I was not comfortable with the box moving every time a plug was inserted into the receptacle.
(Not to worry- the leak had been solved, but the owner was not about to replace the entire wall!)
I am not all that concerned about any reaction between the foam and the cable jacket. Those foams are like an epoxy; rather than a solvent, they contain two materials that react with each other. Oddly enough, the "second" component is sometimes moisture in the air!
That aside, the liberal use of foam is, in my experience, a sure sign of a third-rate contractor. Foam is not cheap, either. I might not be able to cite for the use of foam ... but I sure can take that as a hint to look closer!