Originally it was composed of small-farmers, who turned out to defend their property and to pinch the property of others to get land for their sons. The unpropertied class was exempt from service, as it was thought that it was not fair to make them fight for others’ property, and as they had no motivation they would be unreliable anyway.
This ended at the close of the 2nd Century BCE when the Germanic invasion required much greater numbers, and the non-propertied classes were enlisted. That caused a social upheaval as they became dependent on their generals for pay, loot and land for resettlement. The generals thus had a following which they used to advance their own power and political interests. This was in large part responsible for the civil wars of the 1st Century BCE, and lasted until Augustus took control, and allocated all the legions to himself, so there was but one general with army backing. Thereafter the army was professional.