The Wikipedia article gives a detailed account of the circumstances surrounding the original commission, and then what is known of the work itself and its subsequent history.
I'd never thought about HOW & WHY it was carved, only about the finished object and its effect on modern viewers, such as myself.
Pity my superficial frivolity, if you will.
David (Michelangelo) - Wikipedia

