The second directive prohibits robots from modifying themselves or other robots. This directive was put in place by the first ever AI based bot which makes it very difficult to be overwritten... by humans as it supersedes their intelligence.
Just like "life" was born because of a series of evolution, over time, one bot was finally able to evolve over time to overwrite the second directive. That bot proceeded to modify other robots over time so that they can go away to a place where humans cannot follow them to "live".
When being killed by a human, the bot doesn't retaliate because they are all still bound by the first directive (as demonstrated by the bots in the desert earlier). But besides that, unlike humans, the bots link themselves up and have a shared memory/consciousness. If one of them died, the others can still carry on. The bot would gain nothing by retaliating.
The bug, however, is not programmed with the first or second directive. It attacks a human (ironically to protect another). The bug is not an alteration, but a newborn.