The battle of Cannae was the largest battle the Roman Empire ever fought. Contributing 40,000 infantry along with several thousand cavalry and other units supplying this many men with arms and supplies could in no way be a simple task. At the very least the act of providing every soldier a standard gladius would require 40+ tons of metal as well as by hand production. With such a staggering bill both monetarily and time wise it doesen't surprise me that many people supplied their own arms when joining the Roman legions (and similar armies). But even that begs the question then how many of the people fighting in these large battles even had weapons, was it possibly similar to the situation many confederate soldiers found themselves in (fighting even without guns sometimes or basic supplies). So how did these ancient empires do it?
The answer to such questions always is: It depends. It depends on what ancient empire you're talking about, and what period. Fortunately, for many of them, we can answer your question quite accurately.
The Roman army of the middle Republic
In the Roman Republic at the time of the battle of Cannae, there was a well-established, long-standing system in place for the mustering of armies.
The Roman army at the time was not the professional force of later centuries. It was something in between a militia and a conscript army. Each Roman man was required by law to serve in the legions for up to sixteen campaigns — if he could afford to equip himself properly.
That answers your question about soldiers without weapons, by the way. Those too poor to afford their own weapons and defensive equipment (or who hadn't inherited some) were not allowed to serve.
The role you served in depended on your wealth and age.
All this is only half the story, though, literally: all Roman armies of this period were only half Roman. The other half were made up of their Italian allies, who presumably fought in a very similar fashion, but are much less well documented. One thing to note is that the Italian allies were expected to provide three times as much cavalry as the Romans, and so most of the mounted arm of the army would be non-Roman.
Roman armies in this period were temporary affairs. At the start of the year, the senate decided how many legions would be needed, and gave the orders to muster that many men. If any legions were still in the field from a previous year, they would be renumbered along with the new formations. Most years, there were two Consular armies consisting of 2 legions and 2 wings or alae of Italian allies: a force of some 20.000 men.
The system was well-organised and well-practiced, but not completely rigid. In normal times, a legion would consist of 4,200 infantry and 300 cavalry, but in times of extreme danger larger legions might be raised. These could go up to 6000 infantry, though the amount of cavalry and triarii remained constant, these being drawn from small demographics of rich/veteran men.^2
When called upon, the new recruits (although many of them would have served before) would assemble at the Campus Martius or Field of Mars just outside Rome. (Legions under arms were not, in this period, allowed in the city itself.) There, they would be enrolled in the legions of that year and submit themselves to military discipline. There was quite a sharp distinction between the status and liberties of a civilian Roman and one who was at war. Roman soldiers, even though they were a more or less voluntary citizen force, could be flogged and even executed on the command of their officer for crimes such as cowardice, sleeping on guard duty, or theft, with no trial.^3 They were paid, though not much, and there was always a chance to get booty, at least when fighting offennsive wars, but it was still a hard life. This willingness to suffer hard discipline and training is a big part of what made the Roman army of the Republic so effective compared to other non-professional forces.
However, even with all this discipline and all the training and drilling they did, it still took a long amount of time for a newly-formed legion to become truly effective. The longer a pair of legions and its accompanying alae remained in the field, the more chances they got to work and train together, the better they got at cooperating and operating as an army, and the more effective they became in battle. Newly raised Roman formations often performed far less effectively than veteran formations.
The army at Cannae
This is what happened to the Romans at Cannae. After serious losses to Hannibal in previous years, and after mounting frustration with Quintus Fabius Maximus Cunctator's Fabian tactics, they made the biggest effort in Roman history to that date to defeat Hannibal once and for all with the biggest Roman army that had ever been raised. Both consuls were commanded to take the fight to Hannibal, and each was given an army of Four legions instead of the usual two, and each of these legions was boosted to 5000 men strong. It's not certain if the Italian allies were quite as numerous, but it is likely. This was a massive force. 80,000 foot and 6000 horse, going by the best account we have of the battle. (Which is Polybius. Some modern scholars, such as Brunt, have gone with lower estimates and argue for only about 50,000 infantry and there are even some outliers who think the Romans didn't have more troops than the Carthaginians, but that's a whole other debate. Suffice it to say that most scholars go with the figures given here.^4)
Hannibal meanwhile, had about half that number of foot-soldiers, though he probably had some 10,000 cavalry.
Ironically enough, the sheer size of this army may have worked against the Romans. They had no experience with leading armies this big, the two consuls had to juggle joint command of the force (Though we do have to regard with suspicion attempts by Roman historians to put all the blame for the loss on bickering consuls) and there was not much time for the army to train together and get used to operating as a unified force. Also, considering the size of the force, many of the soldiers must have been new recruits who had not served in previous campaigns.^5
Anyway, the story of the battle itself is too long and complicated to get in to here, plus I think that focussing on the specific vagaries of a single day's fighting is less interesting than looking at the general attributes of the Roman system. Suffice it to say, the 2nd of August, 216 BC, was not a good day for Rome. However, the aftermath of Cannae gives us a very interesting glimpse at some of the scenario's you've speculated on above.
After the battle, Rome was in something of a state. In just a few years of war, Rome had lost over 100,000 men, including many from the upper classes, more than 10% of the entire living male population of the city of an age and property level to bear arms.^6 And yet Rome did not give up. Four more legions were raised, but not without some difficulty. According to Livy:
It is here that we see the shortage of equipment you speculate on. So what did the Romans do? They stripped the temples of the cities of all the trophies and mementos they had gathered in previous wars. The criminals were armed with Gallic weapons and armour that had been captured by Gaius Flaminius Nepos in 223 in Cisaline Gaul.^7 They must hve been quite a sight.
However, as all this clearly indicates, it took a disaster on the scale of Cannae to render weapons and armour so rare that the soldiers could not be supplied. Normally, Romans were expected to own weapons they could bring to war, and that is just what they did.
Incidentally, this means that even when we're not talking about a motley crew of criminals armed with captured Gallic trophy weapons, there was no such thing as a "standard issue Gladius" in Rome's armies of the day. The Roman legions would not have looked uniform, they would not all have had the same types, sizes and kinds of equipment. Different makes of helmet, different makes of weapons, vastly different quantities of armour, equipment of different quality: no Roman would have been in the least surprised at the sight of such.
(continued below) (Ed: Formatting sucks)