The nuts and bolts of the answer to your question are here in the answers above from mr. tom and TTFrenzy.
The final in which Ding Ning got injured and still pulled out the match, that mr. tom mentioned was the WTTC singles FINAL. Which means Ding Ning may not be the current Olympic Champion. BUT SHE IS the current WORLD CHAMPION. The current Olympic Champion won her spot in the qualification tournament. That is Li Xiaoxia. Which also means that if Ding Ning wins the semi-final and goes to the finals, it will be The Current World Champion vs The Current Olympic Champion. Just like with the men: ML = Current World Champion, ZJK = Current Olympic Champion.
As to why and how, TTFrenzy has answered the how.
In the Olympic Qualification rules for Rio 2016, the first method for qualifying was the Qualification tournament. ML won the first round of the men's. Li Xiaoxia won the women's. China could have left their remaining players in those tournaments and let the best man and woman standing, be the second qualifier. I would have liked that. Because then the players who qualified would have earned their spots.
But, there was another option that China chose to utilize because it meant that they could choose their second qualifier. A choice they did not have in London 2012. The second option was that, in the April (or was it May?) 2016 OLYMPIC Rankings (Not the World Rankings but based on them), the highest ranked player remaining, would be invited for any given country. I can't remember what the ranking cut off was. In 2012, the ranking qualification was for players in the top 28. But I would have to look at the Olympic qualification rules for Rio to know where the cutoff was for Rio: the last time I looked was in April; too long ago for my memory. Regardless, the cutoff did not apply to China anyway. The country could accept the invitation or reject it. The country could reject a certain number. I can't remember if that was 2 or 3.
For men's, China rejected 2 (FZD and XX) before accepting ZJK. For women's I believe they only rejected 1 (LShiwen) before accepting Ding Ning.
So, China was within the rules. Hopefully the IOC will look at how that played out and decide if they think it was fair that the rules they instated allowed China to pick its 2nd qualifying players for Rio.
The scenario I just explained, there is no other country that is in a position to have a 3rd or 4th ranked player on their team that they would accept over a 1st, 2nd or 3rd ranked player. No other country is that deep. So, perhaps the IOC did not think of the scenario.
But, perhaps the IOC likes the idea that, if they can't avoid having China have both spots in the gold medal match, at least both matches are Current World Champion vs Current Olympic Champion.
In 2012 the rules were different and seriously flawed. The first 2 qualifying players in 2012 were chosen based on World Ranking in the June 2011, right after the WTTC finished. At that time Wang Hao was ranked 1st, Zhang Jike was ranked 2nd, Timo Boll was Ranked 3rd, Ma Lin was ranked 4th and Ma Long (who was coming off an injury) was ranked 5th. If the rules were the first 2 players in the rankings as of any time after October of 2011 and certainly by April 2012, Ma Long would have been in the 2012 Olympics. But the first 2 qualifiers were chosen based on world rankings that were 15 months before the start of the London games because the June 2011 World Rankings came out on May 15th.
I think the qualification process for Rio was better. But, I think it was still flawed. One positive side of how China handled things by pulling out after they had 1 player qualify for singles was: THEY LEFT MORE SLOTS FOR PLAYERS FROM OTHER COUNTRIES TO EARN THEIR SPOT THROUGH THE QUALIFICATION TOURNAMENT.
I hope this information helps. But if anyone wants to do a google search for Olympic Qualification Process Table Tennis, it is easy to find the rules for both 2012 and 2016.