“spirit.” It is very hard to tell whether it is more proper to say “Spirit” referring to God, or “spirit” referring to God’s gift of holy spirit when translating this verse. The Greek had no such problem because every letter was either capital (in uncial manuscripts) or lowercase (in minuscule manuscripts). God works seamlessly with people through the agency of His gift of holy spirit, which He puts upon people (and now is born and sealed inside people; Eph. 1:13-14). It was God who originated the words David spoke, but like any prophet, he spoke them because he was energized by way of the gift of holy spirit that was upon him (cp. 1 Sam. 16:13). We used “spirit” here, knowing that the English “spirit” limits what actually transpired to the gift of holy spirit upon David energizing him, but knowing that the educated Christian knows that the gift of holy spirit never acts on its own, but is energized by God. (Cp. Mark 12:36; Acts 1:16; 4:25, which are the other times when David is said to speak by spirit).
It seems in keeping with the flow of the context and standard OT usage that Jesus is saying that David was speaking “by” (or “in association with”) the gift of God. In other words, it seems more likely that Jesus is saying David is speaking by the spirit of God (i.e., not on his own) than saying that he was speaking, being directed by God Himself, although it may well be that is indeed the emphasis here; it is very hard to tell, and it bears repeating that the original text did not make a difference between spirit and Spirit. Also adding weight to the fact that this is likely a reference to the gift, not the Giver (God) is the fact that ἐν πνεύματι is clearly used of the gift of God in other places (cp. Matt. 3:11; Mark 1:8; Luke 3:16; 11:13; John 1:33; Acts 11:16; Rom. 9:1; 14:17; 15:16; 1 Cor. 12:3; 1 Thess. 1:5; Jude 1:20), but not once clearly used with God Himself.
The Old Testament context of speaking out in prophecy because a person has the spirit of God upon them is well established (and “upon,” as per the KJV, is a good rendition of the Hebrew and very accurate, in contrast to some modern versions). Many people spoke or acted prophetically when the spirit came upon them (cp. Num. 11:17, 24, 25; 24:2, 3; Judg. 3:10; 1 Sam. 10:6, 10; 1 Chr. 12:18; 2 Chr. 15:1; 24:20). That would make this verse in Matthew similar, and show David to be following in that prophetic pattern.
The REV has “by the spirit,” adding the word “the” even though the Greek text does not have it. The Greek reads en pneuma (“in spirit;” ἐν πνεύματι), but the definite article is not needed in prepositional phrases to make the noun definite. Daniel Wallace writes: “There is no need for the article to be used to make the object of a preposition definite. ...This is recognized by most grammarians.”a Thus, when prepositions such as en, dia, or hupo are used before the noun pneuma hagion, as occurs here in Matthew, the noun can either be definite (i.e., “the pneuma”) or indefinite (i.e., “pneuma”) depending on the context or what reads most smoothly in English, because sometimes “the” just refers to “the” spirit in the context or the spirit that is commonly known.