One time, when David was trying to get God to stop killing thousands of innocent people to punish David for obeying God, David decided he had to make God a sacrifice. When someone offered to give David some free oxen to sacrifice, David said that wouldn’t work. It wouldn’t be right to offer God something that cost him nothing. That wouldn’t be a real sacrifice at all! So he paid for the oxen and then sacrificed them, and God accepted his offering and stopped killing innocent people.
But what about that other time, when Abraham had just passed God’s test by showing how easily he could be convinced to murder his own children? In that story, God provided Abraham with a free ram, just so he could offer it right back to God. Here God certainly doesn’t seem to have a problem with people giving him things that cost them nothing. Instead, he’s actively encouraging it.
And when Joshua had the Israelites destroy the city of Jericho, he said God wanted them to plunder all its people’s valuables and put them in God’s treasury. The Israelites certainly didn’t pay for those stolen goods, but apparently God wanted to have them anyway. As long as you’re giving him valuable stuff, God doesn’t seem to care how you got it.
Possible explanation
David was wrong. All God cared about was getting those burnt oxen, and he would have been happy even if David had stolen them for him.