There are several different accounts of how a "hat trick" was celebrated in the history of the NHL. Each have varying degrees of similarity, but all involve a hat being awarded to any player who tallied three goals.Typically the word "haberdashery" is also included, which is fantastic.
I'm not sure how that evolved into fans throwing their hats onto the ice to acknowledge the feat, but that appears to be the tradition that hockey fans have stuck with. It is a relatively harmless exercise, and hats can't really be weaponized to pose a threat to anyone. Until anyone comes up with a better idea to celebrate a trio of goals, I suppose we'll continue to toss our used lids to the ice.
My idea of releasing a family of raccoons on the ice was innovative and entertaining, but relatively dangerous and potentially inhumane. Here are some other items that have found their way onto the NHL playing surface.
Note to all you young whippersnappers: If you throw something other than your hat onto the ice, you will be abruptly asked to leave by an unpleasant member of arena security. Just because you paid to sit close to the ice, does not give you the right to throw stuff onto it. Enjoy the game and stop smuggling ocean and jungle creatures in your pants.