Look into Player Groups and Unit Groups. The Pick Every Player function and Pick Every Unit function can achieve this.
The idea being that you would have a trigger that Picks through each active user (player), figures out their race, and removes the appropriate workers.
Pick every player in Users -> If Race of Picked player Equal to Undead -> Set Variable Counter = 0 -> Pick every unit owned by Picked player of type Acolyte -> Set Variable Counter = Counter + 1 -> If Counter <= 2 then Remove Picked unit.
So you would only remove 2 of their 3 acolytes if they were the Undead race. This is because Counter counts up by 1 for each Acolyte and once Counter reaches 3+ it would no longer be <= 2 and thus it would not Remove any more Picked acolytes.
You can then add extra If Then Else statements for the other Races. Then you could set unique numbers for what Counter needs to be for each of them. So if you wanted Human to only get 2 Peasants then you would set it's condition to check if Counter was <= 3.
This trigger (or just these actions) would need to run AFTER the workers have spawned in.
Did you search for Unit Groups or Player Groups? I'm sure there's visual triggers for these if you dig around. Forgive me for not creating the triggers myself, it's just that I know it's been done before.