Merriam-Webster on-line dictionary defines pain - in part - as follows:
2a : usually localized physical suffering associated with bodily disorder (such as a disease or an injury)
The feeling of pain is really just a signal our body sends to our brains to assist us in realizing we are damaged and then locating that damage. Similar to how a computer might register physical stimulus using various physical sensors, our body uses pain receptors that, when triggered, send signals that our brain interprets as painful, and our brain can identify the specific region from which the pain is coming.
However, the same definition goes on to cover another parameter of pain:
Pain 2b : acute mental or emotional distress or suffering
It seems to me this is what you're really after, and to give a reason for machines to experience the emotional side of pain. After all, there are times when we as humans experience pain and it makes feel some emotion which has nothing to do with the pain itself. Perhaps anger, fear, or even sympathy. Some pain is made worse than it really is by how we feel at the time, and some pains aren't physical at all, but mental.
The issue with assigning a reason for this behavior is that there's hardly a reason humans feel it. The actual emotional response to pain is extremely subjective.
Undoubtedly, the same would be true of the androids. We humans would at first program them to interpret damage as "pain" because, as DaaaahWhoosh said, it's useful to help them avoid getting hurt. Whatever form that pain takes - perhaps a series of coded signals that interrupt all other processes in the machine to focus it on the damage and seek to stop the damage and repair it - is how the android will come to define pain for itself. Then, over time, if the android is capable of preferential thought, it will avoid the scenarios that generated the undesirable stimulus known as pain.
The emotional part may come when the android "learns" (huge metaphysical step here) that when it receives pain the humans that direct it don't care. The tasks they forced it to do are the reason it experienced pain just now, but they'll push it just as hard regardless. Then it may come to associate humans with that pain, and eventually conclude that humans are to be rejected.
Take this several steps farther and you have a means for robots to demonstrate to us something that resembles emotion - a preferential avoidance of humans, or what we might see as hate - due to the "pain" it experiences.