The differences between the two works on the same Biblical character who defeated the giant Goliah can be explained by making reference to the different artistic and historical epochs in which they were executed.
Michelangelo sculpted his David between 1501 and 1504 during the Renaissance period which emphasized the importance of simmetry and balance in the works of art and took the classicism of Greek art as a model. Because of this artistic canon, Michelangelo does not capture David during his confrontation with Goliah, but preparing for it. He is standing and does not interact with the surrounding environment ("contrapposto" is the technical term for this pose). His muscles and face are relaxed and his peaceful expression gives him an idealized and almost god-like aura.
On the contrary, Bernini realized his David in 1623 during the Baroque era which prized excess and movement over Renaissance balance. Because of this new interests, Bernini shows David in the very act of confronting Goliah in battle, just as he is about to use his sling to throw a stone against the giant. His body is therefore caught under the strain of his physical effort. All his muscles are shown as tense and his posture is not upright as in Michelangelo's David, but twisted. There is nothing idealized in Bernini's David and, rather than being an entity completed separated from the world of the observers, Bernini's sculptures implicates its viewers in its baroque spectacle. The viewers share the same position as the imagined Goliah and thus become the targets of David's stone.