They're purchased, traded, or simply given as a gesture of gratitude.
I don't know about the other branches but Challenge Coins are very popular in the Navy. I've got dozens of them.