the Spanish had massive armies and plenty of resources so where the Comanches and Apaches just that tough to beat?
The Comanche and Apachean peoples (along with the Kiowa, who also live in the southern plains) adopted horses and became enthusiastic equestrians. To understand how this made them a highly effective military force, you have to understand a bit about behavioral ecology and cultural evolution.
From a behavioral ecology standpoint, equestrian Plains Indians, despite their reliance on wild bison for food, were less like other nomadic hunter-gatherers and more like pastoralists. Since equestrian Plains Indians relied heavily on horses for transportation, warfare, and hunting, horses became the main form of wealth. Unfortunately for any nomad who holds their wealth as horses, horses are easy to steal. All your savings could be wiped out in a single night by a sneaky horse-raid. Alternatively, you could go from poor to rich overnight if you conducted your own sneaky horse-raid. Everyone has incentives to steal horses and keep the horses they have, violently if they must. The result is that equestrian Plains Indians, like other pastoralists, were racked by endemic warfare.
And if you are racked by endemic warfare, there's strong cultural selection for being better at war. Hence the development of strong warrior cultures on the Plains. Equestrian Plains Indians were smaller scale versions of Eurasian steppe horse nomads, from the Scythians to Huns to Turkic peoples to Mongols. And though Eurasian horse nomads had by the 1800s ceased to be threats to Eurasian states, in the 1800s horses continued to be very important militarily.
So, because they adopted a horse-based nomadic lifestyle, equestrian Plains Indians developed warrior cultures and, through their proficiency on horseback, had enormous war-making capacity relative to other North American Indian societies. So, early on, equestrian Plains Indians were not just able to resist being controlled by settler states; they were actually able to go on the offense. Because of the Comanche and other horse nomads, Mexico lost effective control over much of its north (land that would then be conquered by the US), and the Republic of Texas was under constant threat.