the Psalms were composed with ruach hakodesh/prophecy which means he was a sort of spokesman for the word of God as David himself said:
The Spirit of the LORD spoke through me; His word was on my tongue. (Shmuel II 23:2)
some of the psalms were even intended for our times as can be seen here.
Also, David was the King of Israel which means he was the heart of the nation (this is why there are special mitzvot for the king to guard his heart from going astray) and being the first and foremost king this extended to all generations. Hence, the Psalms are for every jew for all times. Hence, even when he seems to be speaking only about himself, it applies for all jews at all times. (readcant remember the source of this somewhere).