Was it pride (vanity) or a demonstrated lack of faith on Davids part that angered God?
If “the reality is that God didnt justify His actions with a reason, nor does He have to”, you’re talking about Allah of the Muslims, or you’ve fallen for the Muslim influenced error of Voluntarism. Truth is so close to God’s essence that in the psychological analogy of faith, Truth is the Eternal Logos, the Second Person of the Blessed Trinity. (The essential attributes of spiritual beings, whether men, Angels, or God, are to know and to will. The knowledge with which God knows Himself infinitely is the Second Person of the Blessed Trinity, the Eternal logos, the Eternal Word, Jesus.) It’s in Islam that God arbitrarily refuses to give His reasons, and is not bound by rationality. When Jesus said I am the way the truth and the life, He said it in the context of coming into this world to Enlighten all men.