David actually plays quite a lot of the bass parts on Animals, on the album I believe the breakdown of what David and Roger played on the three main songs is as follows, in track order:
Dogs - All guitars - David; Bass - Roger
Pigs - Lead guitar - David; Rhythm guitar - Roger; Bass - David
Sheep - Lead guitar - David; Rhythm guitar - Roger; Bass - David
David thus played bass as well as lead guitar on two of the three songs (albeit with the usual David on guitar, Roger on bass combination on Dogs, which takes up almost all of side one of the LP).
One thing that is slightly odd about this is that Dogs and Sheep both originated from songs originally played on the Dark Side tour in 1974 - 'You've Gotta Be Crazy' and 'Raving and Drooling', respectively, which meant that Roger played bass on not only the early version of Dogs, but also on the early Sheep. Therefore, I'm not quite sure how David ended up playing bass on the final version. Pigs is a different matter, it was a completely new song and therefore I believe Gilmour would probably have come up with the bass solos in the song himself.
In live performances, obviously it was not possible for David to play both guitar and bass and therefore guitar player Snowy White was recruited as an additional musician to play both bass and rhythm guitar in the live shows. Thus the three Animals tracks were played live as follows (Sheep was played first live rather than Dogs):
Sheep - Lead guitar - David; Rhythm guitar - Roger; Bass - Snowy White
Dogs - Guitars - David and Snowy White; Bass - Roger
Pigs - Lead guitar - David; Rhythm guitar - Roger; Bass - Snowy White
It must have been quite strange on the 1977 In The Flesh tour compared to previous Pink Floyd tours because for much of the Animals section, Roger Waters was playing guitar rather than bass, especially once you took into account Pigs On The Wing (where Roger played acoustic guitar). By contrast, Roger to my knowledge played all of the bass on Wish You Were Here, which made up most of the rest of the show. In this part of the performance, Snowy White acted as an additional guitarist supplementing Gilmour's parts, notably on Shine On You Crazy Diamond.
On The Wall, I'm not so sure off the top of my head, partly because there are so many songs on that album (it's a lot easier to remember who played what when there are only four/five songs, not 26!), but I'm pretty sure David played the fretless bass on Hey You. I think he also plays bass on Nobody Home, which doesn't have any guitar parts, but beyond that I'd definitely need to check all of the song credits again.
My only suggestion as to why David played bass on these songs is that he is simply, from a technically point of view, a better musician than Roger. I think I once came across a quote from David where he was asked about who played bass on Hey You, and he politely suggested to the interviewer that it wasn't likely to be Roger playing the fretless bass part. This could explain why David plays bass on this song, and possibly also on Pigs too.
David also played bass on The Narrow Way (Ummagumma) and Fat Old Sun (Atom Heart Mother), but the former song was on an album of solo projects by the four band members and therefore David played all of the instruments himself, while if Wikipedia is correct, Fat Old Sun only features David and Rick, with Rick playing the organ parts and David playing all other instruments, including the drums as well as guitar and bass.
Thanks for the story about Rick tuning Roger's bass - I'd honestly never heard that one before.