Nice question. Well our conscience is part of our sentient ability to be aware of our own actions and choices. I don't know when humans were classed as a sentient species, but somewhere down our evolutionary ladder we began to think with our conciousness and bit by bit stop acting on instinct all the time. There wasn't a set point in time where our ancestors started feeling guilty, our ability to perceive our world and ourselves has developed over millions of years.
As for how, well, it's the way we have evolved. It's a fascinating subject, but I'm simply not smart enough to explain how our brain has developed and what parts of the brain have these chemical reactions taking place that equate to our conscience.
The advantage is, we have the ability to understand ourselves (to a certain extent) and to have the chance to learn and experience the world around us.
Behaviour in lower forms of life is simply chemical, a bee can fly from flower to flower, doing it's thing, completing it's purpose but it can't see the flower. It doesn't think it's beautiful, it just relies on instinct to find the flower and use it for what it needs.