William Binney in an interview suggested that the tech he built for spying on foreign countries was simply retrofitted and used to spy internally.
I am gathering not a lot of people actually knew what was happening at the beginning, and the tools they were using for "valid" purposes were just refocused.