Contrary to popular belief, there is nothing in Data’s programing that would prevent him from doing “bad” things like lying or killing. He has free will just as much as any other Starfleet officer.
Data is much more human than you might guess at first. He is more akin to a human on the autism spectrum than a robot with hard-coded programming.