The answer is in the number of times he asked them.
The apprentices know that there is at least one wise person and at least one unwise person in their crowd. But they don't know if they themselves are wise or not at first.
If the master had only given one of the apprentices a red ball, he would immediately seen that no one else had one and would have stepped forward the first time the master called.
If the mastr had given two of them red balls, they would both have seen one other apprentice with a red ball. So they still wouldn't know if they were wise or not.
The first time the master would call, they would both notice that the other wise apprentice didn't move, which could only mean that the other apprentice could also see a red ball. Therefore, both apprentices would know that they were wise and would step forward the second time the master asked.
Now imagine there are 4 apprentices with a red ball on their head:
the master asks a first time for the wise to step forward. The wise ones see 3 other apprentices with a red ball and so they don't step forward because they don't yet know if they are wise or not.
The second time the same thing happens, and the third time as well.
But the fourth time the master asks the wise to step forward, they realise that if there had only been 3 wise apprentices, they would all havce been sure of it the third time the master asked them to step forward, so they would know that there were four wise apprentices, and therefore that they were wise.
There, sorry for the wall of text but it is a bit complicated to explain :/