16 “If we have forgotten the Name of our God.” Here is the “understanding” of the “sons of Korah.” “And stretched out our hands to a strange God”. “Shall not God search this out? For He knows the secrets of the heart”. He “knows,” and yet He “searches them out”? If He knows the secrets of the heart, what do the words, “Shall not God search it out,” do there? He “knows” it in Himself; He “searches it out” for our sakes. For it is for this reason God sometimes “searches a thing out;” and speaks of that becoming known to Himself, which He is Himself making known to you.
He is speaking of His own work, not of His knowledge. We commonly say, “A gladsome day,” when it is fine. Yet is it the day itself that experiences delight? No: we speak of the day as gladsome, because it fills us with delight. And we speak of a “sullen sky.” Not that there is any such feeling in the clouds, but because men are affected with sullenness at the sight of such an appearance of the skies, it is called sullen for this reason, that it makes us sullen. So also God is said to “know” when He causes us to know.
God says to Abraham, “Now I know that you fear God.” Did He then not know it before then? But Abraham did not know himself till then: for it was in that very trial he came to know himself....And God is said to “know” that which He had caused him to know. Did Peter know himself, when he said to the Physician, “I will be with You even unto death?” The Physician had felt his pulse, and knew what was going on within His patient's soul: the patient knew it not. The crisis of trial came; and the Physician approved the correctness of His opinion: the sick man gave up his presumption.
Thus God at once “knows” it and “searches it out.” “He knows it already. Why does He 'search it out'?” For your sake: that you may come to know your own self, and may return thanks to Him that made you. “Shall not God search it out?”
Source: The Enarrations, or Expositions, on the Psalms (New Advent)