Can you sell the artifacts after you unlock the hats on Temple Run 2 and still keep the hat?
Yes, you can. I don't think about it as "selling" the artifacts but rather having there be an additional reward for finding the artifacts. Originally, there weren't any rewards associated to artifacts but at a relatively recent update they added the additional reward (100-2500 coins, or one or two gems) to artifacts. I've collected the rewards for the ring, mask, critter, floral, relic, Christmas, Valentine, St. Patrick and Easter rewards and all of those hats are still available.
In other words: once you've earned a hat, it doesn't go away.