It'd be perfectly acceptable to give a CM a pin, but they wouldn't be able to wear them at work. At least, not as far as I know. It's, of course, possible to break dress code (some days you just don't have clean black socks!) but if a manager comes by and notices, it is punishable.
I was never given a pin by a guest and don't remember any of my fellow CMs recieving one, but I imagine it would be a great way to return the pixie dust magic. I'm sure the CM would hold onto it as a keepsake to remind them of the nice guests they have encountered. If you have a chance to do this for a CM, I would take it even if they can't wear them at work. CMs get a lot of negativity (I once got yelled at by a guest because it was raining), so any thank you you can give them is very much appreciated.