the Fatwa Department Research Committee - chaired by Sheikh `Abd al-Wahhâb al-Turayrî
The Companions would see firsthand the Prophet (peace be upon him) doing certain ordinary and spontaneous actions that were not related to matters of worship or etiquette. On occasion, the Companion who saw the action firsthand would repeat the action out of love for emulating the Prophet (peace be upon him).
This even included things taking a certain path over a certain tract of ground that the Prophet (peace be upon him) walked upon.
Sometimes, the Companion would do this to remember or recall something else that he or she witnessed that was a part of the Prophet's Sunnah. In this case, the Companion's behavior had a practical purpose. In the example that you mention in your question. `Alî's emulation of the Prophet's laughter gave him an opportunity to recall and convey some very important words of the Prophet (peace be upon him) – in this case, a hadîth qudsî.
This was a practice of the eye-witness among the Companions, and even then, on occasion. The other Companions and the Successors did not adopt those spontaneous and inadvertent actions of the prophet (peace be upon him) as practices, and this shows that we should not either.
Clearly, the Prophet (peace be upon him) laughing on that occasion was not intended by him to be part of the supplication, and it would be wrong for us to make it as if it were.
And Allah knows best.
Source: Islam Today