I am looking for some references, but for now if you were to take away the phrase in parantheses (between the commas), you might find it more easy to understand why the second phrase has this meaning. In the first example, the commas create an empahsis that you don't find in the second.
However, it is certainly not the best way of writing the sentences to portray their finer meanings because as we can see it does lead to a certain amount of ambiguity.
My preferred sentences in relation to the meanings would be:
1) Those students who passed the entrance examination applied for medicine.
2) The students passed the entrance examination and applied for medicine.
If I find a reference, I'll send you a message.
Student or Learner