It's for the same reason people like being dirty talked or dominated. Being spanked arouses some people and turns them on.
I like being spanked by my boyfriend, and I like spanking him, purely because it feels naughty and is a turn on. He also likes both too. We're both switches, so we both like spanking BEING spanked, however he's normally a dominant, and I'm normally submissive.
We don't do it for pain, our primary reasons are that it's good fun, feels naughty and is very sexy.
However some people DO do it because to them, pain, or inficting it on another (willing) subject IS a turn on. As long as it is all consensual and people are happy and enjoy themselves then it's all ok.