If you have fantasies of hurting yourself physically or emotionally it is an unhealthy thing. This can be caused by, for example, mental disorders, traumas, personality disorders, etc.
As Karnonnos wrote, if it is, for example, a spanking then it is fine.