Psalm 16 is a "Confession Psalm" because it directly expresses faith in Yahweh, but it is also a "Messianic Psalm" because it is directly applied to Jesus by Peter and Paul (Acts 2:25-28; 13:35). The Psalm does not change subjects from beginning to end, thus the whole Psalm authored by David is Messianic. While David indeed writes the Psalm, Peter makes it clear that David is not speaking for himself, but the Messiah is speaking through him (Acts 2:25).
This Psalm has four segments of thought:
1) Messiah's cry for deliverance (1-2)
2) Messiah's priority to drink from Yahweh's cup (3-5)
3) Messiah's judgment to accept Yahweh's will as pleasant (6-8)
4) Messiah's confidence that He will not be abandoned in the grave (9-11)
Purpose: Revealing how to pray a prayer of confidence in God's ultimate power to bring you into the place He has promised. As Jesus became the first fruits of the dead (1 Corinthians 15:20), so we shall not be abandoned in death.
Yahweh the Deliverer
Psalm 17 is an "Imprecatory Psalm" and is a cry from David for deliverance from a present enemy. It was written during the time David was fleeing from Saul and is one of five Psalms called "a Prayer" in the “Inscription" (17, 86, 90, 102, 142).
The Psalm reveals four separate reasons David prays for deliverance:
1) David's integrity to avoid violence against Saul (1-5)
2) Yahweh's steadfast love for David (6-9)
3) The enemy's relentless desire to devour David (10-14)
4) David's greater concern than the enemy, to be like “Yahweh" (15)
Notice there are those who are pitiless, like lions, that seek to devour, are only concerned with their own satisfaction, and whose only portion is this present life (10-14). Sometimes such people seek your harm for their own benefit.
Purpose: Revealing how to pray when others are seeking your destruction, while your only desire is to live in Yahweh's image.