Hamlet had an opportunity while he found his uncle praying- did nothing and repented later.
David saw Saul asleep and did not kill him.That brought him the tribe of Benjamin later.
If God be with us, whatever we do would turn out fine.
Does it mean God wasn’t with Hamlet? It is not a conclusive inference- man is only granted the liberty to act and if he doesn’t exercise it for positive activity, he is not granted divine favours.
Hamlet merely regretted his inaction and did nothing further, but David sustained his activity and also took advantage of his generosity by announcing to Saul how his life was in David’s hand.