CAS said it had rejected appeals by the IOC, the World Anti-Doping Agency (WADA) and the International Skating Union to have Valieva's suspension reinstated after it was lifted by Russian anti-doping authorities.
The court cited "exceptional circumstances," including Valieva's age.
Matthieu Reeb, CAS director general, said that preventing Valieva from competing would have caused her "irreparable harm."
CAS also emphasized that "there were serious issues of untimely notification" of the test result.
Valieva gave a sample on Dec. 25 but the result was only produced last week, after she led Russia to team gold.
"Such late notification was not her fault, in the middle of the Olympic Winter Games," the ruling said.
The Russian Olympic Committee hailed the decision, saying: "Tomorrow the whole country will support her."
The US Olympic and Paralympic Committee though said it was "disappointed by the message this decision sends."
"This appears to be another chapter in the systemic and pervasive disregard for clean sport by Russia," it said.
Six-week delay
Valieva tested positive for trimetazidine, which is used to treat angina but is banned because it can increase blood flow efficiency and help endurance for athletes.
It took six weeks for the result of the test to be processed by a WADA-accredited laboratory in Stockholm.
The Russian anti-doping agency (RUSADA) was notified of the positive result on February 8 and suspended Valieva, but she appealed and the suspension was lifted.
RUSADA has said it was informed that the sharp rise in Covid-19 cases at the start of the year was the reason for the delay.
"We would not have this case and I would not be here if these anti-doping test procedures would have been completed in one week or 10 days," Reeb said.
The day before she received the result, Valieva helped Russia win the figure skating team title, producing a dazzling performance as she became the first woman to land a quadruple jump in Olympic competition.
No medal ceremony
The IOC said it had no choice but to allow Valieva to compete in the singles event but "in the interest of fairness to all athletes" it will not hold a medal ceremony in Beijing if she finishes in the top three.
The IOC also confirmed that the team event medals will not be awarded during the Games for the same reason.
Earlier, referring to the team event medals, IOC spokesman Mark Adams said: "It's a dilemma we are all in and it's something we're not happy with."
The United States won the silver medal in the team event and Japan took the bronze, with Canada fourth.
WADA meanwhile said it was investigating Valieva's entourage, which includes highly successful coach Eteri Tutberidze.
CAS's decision will be intensely scrutinized because Russia is already under sanctions for a massive state-sponsored doping program that reached its peak at the 2014 Sochi Winter Olympics.
As a result, Russians are competing in Beijing only under the flag of the Russian Olympic Committee (ROC).
French dazzle
In Monday's sports action, Californian-born Eileen Gu, the face of the Games after winning freestyle skiing gold for China last week, held her nerve to qualify for the slopestyle final.
The 18-year-old was down in 11th place after a mediocre first run, and with only the top 12 going through to Tuesday's final, the pressure was on.
Gu duly delivered to finish in third place.
French figure skaters Gabriella Papadakis and Guillaume Cizeron won Olympic gold in ice dancing, breaking their own world record again in the process.
Papadakis, who suffered a problem with her costume that cost the pair the gold medal four years ago, said: "I think we don't believe it yet. Honestly it feels completely unreal.
"We have been waiting for this."
Canadian-born Kaillie Humphries won the inaugural monobob event — and dedicated it to her adopted USA after switching allegiance amid claims of mental and verbal abuse.
"This will always hold a special place in my heart, my first for the USA," said Humphries, the first woman to win Olympic bobsleigh medals for two nations.
A Message from The Moscow Times:
Dear readers,
We are facing unprecedented challenges. Russia's Prosecutor General's Office has designated The Moscow Times as an "undesirable" organization, criminalizing our work and putting our staff at risk of prosecution. This follows our earlier unjust labeling as a "foreign agent."
These actions are direct attempts to silence independent journalism in Russia. The authorities claim our work "discredits the decisions of the Russian leadership." We see things differently: we strive to provide accurate, unbiased reporting on Russia.
We, the journalists of The Moscow Times, refuse to be silenced. But to continue our work, we need your help.
Your support, no matter how small, makes a world of difference. If you can, please support us monthly starting from just $2. It's quick to set up, and every contribution makes a significant impact.
By supporting The Moscow Times, you're defending open, independent journalism in the face of repression. Thank you for standing with us.
Remind me later.