How did Ash Ketchum get his famous iconic hat?

He won it during an exhibition Pokemon battle

He mailed a million post cards for it

His mother gave it to him as a parting gift

The hat belong to his father