I suppose that gravitational waves may be ever so slightly attenuated as they pass through matter, but the coupling is so weak that we probably wouldn't notice. (Think of how hard LIGO had to search before they found the first black hole merger signal.) So even for waves, the gravitational effects of the sun would be all but unaffected by Mercury or Venus being in the way.
For a static 1/r^2 field, intervening matter has very little effect at all. (There are non-linearities in principle, but for all but the most extreme configurations they're negligible in practice.) Certainly when the Newtonian approximation holds you can just add up the separate 1/r^2 effects of all the separate sources to find the overall effect. (This, by the way, is very similar to the behavior of electromagnetic fields. The waves are attenuated or blocked by intervening matter fairly easily, but it takes a pretty special situation to actually block the 1/r^2 effects of a static electric or magnetic field: you'd need to surround your system in a conducting "cage" that would polarize in response to an external electric field to cancel out the effects of that field inside, for example. That isn't possible for gravity, since there doesn't exist negative mass to do the screening.)
Ultimately, the 1/r^2 rule really is intimately connected to the three dimensions of space in our universe. In theories with additional spatial dimensions, that rule changes. Many theories with extra dimensions follow the Kaluza-Klein model, where the extra dimensions are "curled up" very small (in the sense that if you were to travel a distance L in that extra dimension, you'd come back to where you started: like a little circle). In the case of one extra dimension like that, if you were to measure the behavior of gravity over distances much shorter than L, you'd find that the gravitational force fell off like 1/r^3, but if you measured its behavior over distances much longer than L you'd find the familiar 1/r^2. (And for that reason, we know that the L for any system like this must be very small: my memory is that direct gravity measurements can set a limit like L<1mm or maybe even L<1 micron, and indirect evidence from things like particle physics observations pushes the limit down to the nuclear scale or below: L<10^(-15) m or even much less. I probably ought to know the actual values of both of those limits off the top of my head, but it's been a while since I looked at it.)
For a static 1/r^2 field, intervening matter has very little effect at all. (There are non-linearities in principle, but for all but the most extreme configurations they're negligible in practice.) Certainly when the Newtonian approximation holds you can just add up the separate 1/r^2 effects of all the separate sources to find the overall effect. (This, by the way, is very similar to the behavior of electromagnetic fields. The waves are attenuated or blocked by intervening matter fairly easily, but it takes a pretty special situation to actually block the 1/r^2 effects of a static electric or magnetic field: you'd need to surround your system in a conducting "cage" that would polarize in response to an external electric field to cancel out the effects of that field inside, for example. That isn't possible for gravity, since there doesn't exist negative mass to do the screening.)
Ultimately, the 1/r^2 rule really is intimately connected to the three dimensions of space in our universe. In theories with additional spatial dimensions, that rule changes. Many theories with extra dimensions follow the Kaluza-Klein model, where the extra dimensions are "curled up" very small (in the sense that if you were to travel a distance L in that extra dimension, you'd come back to where you started: like a little circle). In the case of one extra dimension like that, if you were to measure the behavior of gravity over distances much shorter than L, you'd find that the gravitational force fell off like 1/r^3, but if you measured its behavior over distances much longer than L you'd find the familiar 1/r^2. (And for that reason, we know that the L for any system like this must be very small: my memory is that direct gravity measurements can set a limit like L<1mm or maybe even L<1 micron, and indirect evidence from things like particle physics observations pushes the limit down to the nuclear scale or below: L<10^(-15) m or even much less. I probably ought to know the actual values of both of those limits off the top of my head, but it's been a while since I looked at it.)