Yeah, might work.
My concerns include potential moisture entrapment problems, especially if there's ever a leak
and
the mess it would make for you if you ever need to get into the wall to work on that plumbing.
If I were considering it, I think I might do a little playing around with the foam first, to get a real world idea about its volumetric expansion rates.....
Maybe even make a little mockup of the wall so you could get a visual of how it might act
I tried something similar once.... I was trying to attach something to a hollow core door, approx eye level. On a whim I bought some of that foam and squirted it in before passing the bolts through. My thought was that it might fill the void to add a little support to the skins. I'm not convinced that it did any good. I had the feeling that most of the foam dripped down inside the cavity before it had a chance to expand where I needed it.
__________________
|