In a lot of games, it's common to have so-called archers and slingers units/squads of around 50-100 people all with the exact same weapons that are specifically arranged and taught a single weapon. Or even more specific greatsword/spear units who only carry these weapons. Are these real? Did medieval and roman generals really organize their armies in such specific ways? Or was it more like, get a weapon, get a squad does what feels right in battle? If the former really did happen are there any specific examples?
Not specifically in the way that you see in Total War games, but somewhat.
Obviously your question covers a vast region and many centuries of time, so answers can be varied. But generally, in the times before professional armies, soldiers provided their own weapons. Soldiers of a higher social class would arm themselves with more expensive equipment.
If you were rich, then you probably owned horse(s) and were able to equip yourself with better weapons. This is basically how we have 'knights', and their cultural equivalents. People were not assigned to be horsemen by some general ordering up troops. If you were rich and you went to war, then you went with your kinsmen and friends who were of similar upper class, and you went mounted, with fancier gear than the poor guys. You'd fight in a group like this, because it isn't great to have mounted troops mixed up with infantry for obvious reasons.
In ancient Greece, citizens of city-states were expected to equip themselves as a hoplite. You'd need shield, helm, spear, and typically some armor. You'd fight in a tight formation with other guys armed similarly, because it is advantageous to have a tight wall of shielded spearmen that are tough to break. Poorer/younger men would fight as skirmishers using slings, javelins, and much lighter (cheaper) armor.
Mercenaries would often be hired from some region that fought in a certain way. For example, the Balaeric Islands were famous for their slingers. If you hired a bunch of guys from the isles, they'd largely be equipped with slings, and they'd generally fight alongside each other.
Rome was somewhat different than others in that it had rather standard equipment for its Legionaiires as they were a professional force. Typical Roman Legion would have a big scutum shield, a gladius sword, and pila (javelins). They would be supplemented by allies/mercenaries/auxiliaries that were armed differently, because they would be from a different culture. You might see a Roman Legion marching to war all equipped pretty similarly, but accompanied by some archers from Crete and horsemen from Numidia, led by a general protected by Germanic bodyguards.
The whole concept of 'squads' is kind of off for the time period. In most pre-modern armies, troops were organized according to personal and kinship loyalties. So the Duke of Brabant would show up with his retinue and vassals, and so on. You would often be fighting alongside men you knew personally through bonds of patronage or kinship, rather than being assigned to the '12th Regiment of Spearmen' or the like. Highly organized armies with specific uniforms and units wasn't something that really existed in ancient times. Standing armies as a whole weren't really a thing for most societies - men would gather for a campaign that was typically very short, and then return to their own lands when it was over.
So, in answer to your question: Kinda. It doesn't happen because a general is ordering up units from a troop recruitment menu. Fighting men would grow up learning the fighting traditions of their locality and social class, which would often emphasize certain weapons over another. Men who lived in the steppe would already be skilled horsemen who used a bow to hunt, while mountain shepherds would likely be more skilled in loose formation and skirmish style of warfare. Aristocrats would be able to afford more expensive equipment and would be trained in its use.