I think you can just ask them. It's not an insult, cos you may never have even heard of the show they are from. Or you could be like, "I love your costume. The character looks so familiar, but I can't remember their name."
If they look very not confident, then I think it would be fine too. Compliment them on the costume and then ask them what the character is. I'm sure they don't expect you to know every single character.
Tell them you like their costume, and if you're uncertain, ask what character they are I also don't randomly go up and hug people in costume, mostly because I wouldn't do that to a person that wasn't in costume... being in a costume doesn't automatically call for invading someone's personal space