Update - WH Statement
According to the White House spokesperson Sean Spicer, Trump seemed to have requested the resignation of Flynn due to a "trust issue".
President Donald Trump asked for Michael Flynn's resignation after he lost trust in his national security adviser for misleading Vice President Mike Pence over his calls with Russia's ambassador, the White House said Tuesday.
"The level of trust between the President and Gen. Flynn had eroded to the point where he felt he had to make a change," Spicer told reporters. "The President was very concerned that Gen. Flynn had misled the vice president and others."
Trump therefore felt he could not trust his top foreign policy right-hand and on key national security issues like China and the Middle East, Spicer said.
(emphasis mine)
Basically, he resigned due to violating the Logan Act and causing embarrassment to the Trump administration.
The Logan Act specifically states:
Any citizen of the United States, wherever he may be, who, without authority of the United States, directly or indirectly commences or carries on any correspondence or intercourse with any foreign government or any officer or agent thereof, with intent to influence the measures or conduct of any foreign government or of any officer or agent thereof, in relation to any disputes or controversies with the United States, or to defeat the measures of the United States, shall be fined under this title or imprisoned not more than three years, or both.
(emphasis mine)
According to this BBC article which includes a timeline of the events, Flynn first spoke to the Russian ambassador in the US on Dec 28:
28 December: Mr Flynn and Russian ambassador to the US, Sergey Kislyak, exchange Christmas text messages by mobile phone
Flynn then spoke to him after Obama introduced sanctions on Russia:
29 December: US President Barack Obama announces sanctions expelling 35 Russian diplomats for the country's alleged interference in the US presidential elections
29 December: Mr Flynn holds a phone call with the Russian ambassador
Flynn took office together with President Trump and his executive team:
20 January 2017: President Trump and his executive team, including Mr Flynn, take office
So, Flynn is still considered a private citizen before he took office on Jan 20. Thus, it's a violation of the Logan Act.
As for prosecution, no one has been prosecuted under this act.
This article by Vox states:
No one has ever been prosecuted under the Logan Act, but Flynn is facing a second and potentially far more dangerous investigation. The FBI is actively probing Flynn’s interactions with Kislyak, and resigning from his White House post won’t shield Flynn from potential future criminal prosecution.
Flynn resigned to avoid embarrassment to the Trump administration since he misled both the public and the Trump administration yet the Trump administration publicly defended him.
As he stated in his resignation letter:
"I inadvertently briefed the Vice President-elect and others with incomplete information regarding my phone calls with the Russian ambassador. I have sincerely apologized to the President and the Vice President, and they have accepted my apology."
He denied the contact with the Russian ambassador in an interview on Feb 8.
In a Feb. 8 interview with The Washington Post, Flynn categorically denied discussing sanctions with Russian Ambassador Sergey Kislyak, repeating public assertions made in January by top Trump officials. One day after the interview, Flynn revised his account, telling The Post through a spokesman that he “couldn’t be certain that the topic never came up.”
(emphasis mine)
Even the Vice-President Mike Pence defended him:
Pence said in a Jan. 15 appearance on CBS’ “Face the Nation” that Flynn’s conversations with the Russian Ambassador Sergey Kislyak were “strictly coincidental” and had nothing to do with the Obama administration’s decision to punish Russia for meddling in the November election, which U.S. intelligence agencies agree was intended to help boost Trump's prospects. “They did not discuss anything having to do with the United States’ decision to expel diplomats or impose censure against Russia,” Pence told CBS.
(emphasis mine)
And the White House's Press Secretary:
Pence wasn’t the only administration official to explain away Flynn’s contact with the Russian envoy. Press Secretary Sean Spicer, then a transition official, said Jan. 13 that Flynn’s calls were about scheduling a call for Trump and Russian President Vladimir Putin after the swearing in. “That was it,” Spicer said at the time. “Plain and simple.”
(emphasis mine)
So, this caused embarrassment for the Trump administration since they misled the public.