The reason why the textbook says that Yunnan was only included in the Chinese territory during the Yuan Dynasty should be divided in an administrative sense.
In ancient times, Yunnan was also under the jurisdiction of the Central Dynasty, but most of them existed in the form of vassal states or special administrative regions, just like Hong Kong and Macao today. It is certainly China's territory, but they have a high degree of autonomy.

Many times Yunnan used the name of the Central Plains Dynasty and laws and systems, the emperor of the Central Plains Dynasty just did not send officials to govern it, and during the Yuan Dynasty, the Central Plains Dynasty strengthened the governance of this place, and politically Yunnan belonged to the central government.
In the Warring States period, the Yunnan region was first subject to the restrictions of the State of Chu, and later Qin Shi Huang set up Guilin County and Xiang County here to directly govern Yunnan, Guizhou and other regions.
Because of its remoteness from the central political bloc, the jurisdiction is not thorough. It is ostensibly a kind of governance, but the local armed forces and the people have a high degree of autonomy.
Due to the relatively short existence of the Qin Dynasty, the Western Han Dynasty later took over the world and once again strengthened the management of the Yunnan region, but also the central government did not directly send officials.
According to historical records, after Emperor Wu of the Han Dynasty conquered Yunnan, Yizhou County was set up to administer this.
However, the specific rulers of Yunnan were directly selected from the local armed forces, and Emperor Wudi of Han crowned him as the King of Dian, existing in the form of a vassal state and directly subject to the jurisdiction of the central government, for example, there was an idiom called "Han Xi Lou Ship" officially from a historical story of Emperor Wu of Han's conquest of Yunnan.
The Han Dynasty's rule over the Yunnan region lasted until the end of the Eastern Han Dynasty. After the decline of the imperial family, the Dian king of Yunnan had a high degree of autonomy and administrative power, and once developed into an independent small dynasty completely free from the control of the Central Plains.
It was not until after Liu Bei entered Shu that in order to avoid the enemy of Yizhou, Liu Bei sent troops to try to conquer Yunnan when he was alive, but did not achieve significant results.
After Zhuge Liang came to power, he began to change Liu Bei's previous strategy and successfully surrendered the rule of Yunnan through the story of the seven captures of Meng.
As in the Han Dynasty, although Zhuge Liang conquered Yunnan and other places, he did not directly send people to administer this area, but only let local officials exercise jurisdiction, but they had to obey the command and leadership of Shu Han. For example, the well-known person Ma Mo was once a Taishou in Yunnan, with such a name, but he rarely went to Yunnan to work locally.
On the surface at that time, Yunnan was not included in the territory of the Central Plains Dynasty, after all, the Shu State had not yet unified the Central Plains.
Later, during the Jin Dynasty, due to wars and other geographical reasons, Yunnan gradually dealt with the rule, and until the Song Dynasty, it existed as the Dali State. The state of Dali was then subordinate to the Song Dynasty, and accepted the canonization of the Song Dynasty, paying tribute to the Song Dynasty.
Coupled with the complex geographical environment of the mountains in Yunnan, the Song Dynasty has always faced military pressure on the north, so it has never crusaded against the Dali State until the later Yuan Dynasty destroyed it.
After the Yuan Dynasty unified Dali, Dali did not break away from the control of the Central Dynasty.
Therefore, the book will say that since the Yuan Dynasty, Yunnan has been included in the territory of China.