Mark Zuckerberg in federal court Monday was forced to revisit a time when he doubted Facebook would be able to compete in mobile photo sharing, and decided to buy Instagram—testifying in a trial where the U.S. government is arguing it should unwind that acquisition.