Many of these places weren't homes. The vast majority of prehistoric people did not live in caves. And many places with art are nearly inaccessible, and completely dark.
Even if most didn't live in caves, if enough of them spent enough time there they would surely end up painting something. And caves are good places for paintings to survive.
I'm not even sure one could separate religious and non-religious purposes. I think there was much less of a distinction. Even in ancient Rome, the gods were involved in many everyday activities, it would surely have been even more so in the Stone Age