The hat comes to a stop, thinking of a plan. The hat had been pacing around for a while, trying to think of how to get off the head he's resting upon and back into the house where it's nice and cozy, and came to the sudden realization of a plan. This caused the hat to stop.
The plan that made this hat stop right in its tracks was very simple. First, obtain the key (き) to the house. Then, use the key to get in the front door. How simple!