Why is it that Mandarin and Cantonese are considered dialects of Chinese but Spanish, Portuguese, Italian, and French are considered separate languages and not dialects of Latin?
It is political. The different so called Chinese dialects are unintelligible to each other. Others have mentioned the Serbo-Croatian-Bosnian example but something similar happened with Romanian. In Moldova they speak Moldovan and Erie it in the cyrillic alphabet. Why? Because when they became part of the USSR it wad decided they didn’t speak Romanian and they had to come up with grammar books for Moldovan using the cyrillic alphabet.
Other times it’s not so clear cut. Depending on who you ask galician is a dialect of Portuguese or a separate different language. For context, a galician and a Brazilian can have a conversation with each speaking their own tongue they just can’t speak each other’s tongue.
So, other excellent answers have highlighted that there is no hard distinction between dialects and languages, but I wanted to add one thing in.
I am really not sure that Mandarin and Cantonese are considered dialects. Yes, a lot of people in the west would refer to a person as ‘speaking chineese’, but wouldn’t think of mandarin and cantoneese as the same language, rather were just being imprecise with their word choice earlier.
I speak Cantonese and I’d argue that despite sharing a common written system, Cantonese and Mandarin are two separate languages, not dialects. Sure, if I listen carefully I can pick up a Mandarin word here and there but the two are basically mutually unintelligible. There are many, many variants of both languages throughout the region, and I’d say that those variants are the actual dialects.
From another perspective, many people tend to class Mandarin as a language and Cantonese as a dialect. Cantonese is actually far closer to Middle Chinese than Mandarin is – so perhaps it’s the other way around.
In Arabic, we speak in really different dialects. For example, a Yemeni and a Moroccan would need a translator between them even though they’re both officially speaking Arabic. Why? Pan-Arab Nationalism. Lebanese actually tried to be its own language once but that never caught on.
There’s a saying in linguistics: “A language is a dialect with a flag and an army.”
The field of Linguistics does not actually define what is a “language.” Linguistics definitely has the concept of a dialect, and can discuss whether two groups of people speak the same dialect or different dialects. It has concepts of things like mutual intelligibility, i.e. can native speakers of two dialects understand each other. But the idea that two dialects are part of the same “language” is a question that linguistics entirely cedes to the field of politics.
So, the answer to your question: China considers itself a single political unit, and they place a high value on considering themselves unified. France, Italy, Spain, and Portugal consider themselves distinct political units from each other, and modern Italy considers itself distinct from the Roman empire.
It’s also worth noting that people from different regions in Italy sometimes can’t understand each other, because dialects of Italian have a very large spread. Again, they’re considered the same language because Italy wants to perceive itself as a single unified cultural entity.
Were one of these regions of Italy to become independent, it’s likely they would consider their dialect to a language over time, although that process would likely involve doubling-down on the regionally-distinct features of that dialect, and probably having a distinct literary tradition as well. Something like this [already happened](https://en.wikipedia.org/wiki/Norwegian_language_conflict) when Norway became independent of Denmark.