As soon as I read this Psalm I try to place it chronologically. It certainly seems to be in the time of David, or maybe it could be in the time of Solomon. Probably Solomon now that I think about it. While he isn’t mentioned by name there is a strong request to forgive David of his past misdeeds. Something a son would want for his father’s legacy. They would have been legendary by the time Solomon came around. But we also have the words of Uriah, the husband of Bathsheba, given to David as the king swears not to enter into his own home until the temple is completed. It is the same action that Uriah takes when he is sent home as David tries to make up for his son by having Uriah sleep with Bathsheba. And yet we know that the temple is not built until Solomon. So, somehow David is given credit for building the temple here, or at least really wanting to, when we know that it was Solomon who ended up building it.
He then shifts from speaking about David’s praises to speaking about the horn that will sprout up from David and that this son will then be the one who will be the Lord’s favorite. That is definitely speaking about Solomon so maybe, just maybe, this is Solomon who is writing this. He is making up for his father’s misdeeds and still he is able to speak about the one who would be coming up after David, that would be him.
It is a great psalm which praises David and at the same time praises all of Israel as the nation which is most in tune with the Creator God.