Unresponsive.
The law, which David was king under, had (has) no provision for even bringing the king to court to convict him of a crime, never mind executing him for it. The king, under the Mosaic Law, answered to God, the Law Giver, not to any judge or court.
This worked because God was...