The righteous will not be exempt from suffering. The Bible is very clear about this. The Bible is full of accounts of the hardship faced by believers. David is teaching his followers that God is present in all troubles.
The lives of his children are precious to Yahweh. He watches over them, even when they die. The imagery of bones is used here to refer to our whole being—heart, soul, and body.
19 Many are the afflictions of the righteous, but the LORD delivers him out of them all.