Hamlet has spent the entire play thinking about what do and thinking about how to do it, and thinking philosophically about why people don't do things. The thing he realizes by the end of the play is that all this thinking isn't accomplishing anything and that he finally just has to ACT and REACT to whatever comes his way.
At the of Act 5 is has decided to go into the fencing match with Laertes. Horatio has warned him that this could be dangerous, but Hamlet responds by saying, "We defy augury; there's a special providence int he fall of sparrow. If it be now, 'tis not to come; if it be not to come, it will be now; if it he not now, yet it will come: the readiness is all." This is a refreshing attitude for Hamlet. He is essentially saying that while God knows about even the smallest events in the universe, we don't, and all we can do is be ready for whatever comes our way. Hamlet is giving himself over to fate rather than cursing it or trying to control it. This new understanding of fate frees him to act. He faces the unknown and accepts that what will be, will be.
At the beginning of 5.2 Hamlet describes what happened on the pirate ship.
Sir, in my heart there was a kind of fighting,
That would not let me sleep. Methought I lay
Worse than the mutines in the bilboes. Rashly--
And prais'd be rashness for it: let us know,
Our indiscretion sometimes serves us well,
When our deep plots do pall; and that should learn [teach] us
There's a divinity that shapes our ends,
Rough-hew them how we will--
Hamlet recognizes that "deep plots" falter and lose force (his plan to avenge his father's murder). And though his rashness led to Polonius' death it does,"sometime serves us well." His learned conclusion is that there is a larger grand design that determines our ends. This is something that Hamlet has failed to acknowledge up to this point.