Hold the hat out in front of you, in an inside grip so that the brim is horizontal, and the crown is on top.
Pull back on the hat as you throw it, so that it floats, without spinning and catch it on your head. Here's what it looks like from the inside.
The key to the trick seems to be to keep the hat level, and pull it towards you as you let go. That and luck, and/or practice.