Google on Wednesday agreed to pay a record $170 million fine and to make changes to protect children’s privacy on YouTube, as regulators said the video site had knowingly and illegally harvested personal information from youngsters and used that data to profit by targeting them with ads.