It turns most hats (and all masks) into gifts that can be given to most villagers which they will then wear.
Some hats are only giftable to certain NPCs due to height restrictions (e.g. Demetrius is just too tall for most hats).
Some hats may not look exactly right on some characters due to hair, etc.
To take back a hat, try to gift the same hat to the NPC a second time.
If you want to complain or ask for help or help me test my mods, you can visit my Discord server.
A list of all my mods for Stardew Valley is available at https://www.nexusmods.com/stardewvalley/articles/895.