Chapter 6 of Maseches Yoma opens with the law of the two goats of Yom Kippur: "Shnei se'irei Yom HaKippurim" - one is a sin offering to Hashem and one is sent away to Azazel, and the lottery is what determines which goat is designated for which purpose.
Their mitzvah is that the two be identical:
The Mishnah teaches that ideally there is a mitzvah for the two goats to be identical to one another: "Mitzvasan sheyihyu shneihen shavin" - in four respects:
"B'mar'eh" - in their appearance.
"U'v'komah" - in their height.
"U'v'damim" - in their monetary value.
"U'lehikachan k'echad" - that both be taken and purchased together.
Although there is a mitzvah in this equivalence, it is not indispensable: "V'af al pi she'einan shavin, kesheirin" - if in the end they did not turn out identical in these respects, they are still valid. So too regarding the law of purchasing them: "Lakach echad hayom v'echad l'machar - kesheirin", even though they were not taken together.
If one of the goats died:
"Im ad shelo higril meis" - if one of them died before the lots were drawn, "yikach zug lasheini" - he purchases another goat as a partner for the remaining goat, and this poses no problem, since the lots have not yet been drawn.
If one of them died after the lottery - "yavi zug acher v'yagril aleihem batechilah" - he brings another pair of goats and draws lots over them anew, and he declares, in the words of the Mishnah, according to the case:
"Im shel Shem meis" - if the goat designated as a sin offering to Hashem died, he says: "Zeh she'alah alav hagoral laShem yiskayem tachtav".
"Im shel Azazel meis" - he says: "Zeh she'alah alav hagoral la'Azazel yiskayem tachtav".
"V'hasheini yir'eh ad sheyista'ev" - the second animal of the new pair, which was not needed, grazes until it develops a blemish. Once it becomes blemished it can be redeemed, "v'yimacher" - it is sold as part of the redemption process, "yiplu damav lin'davah" - and the money received from its sale is given to the fund for donations, from which voluntary burnt offerings are brought in the Beis HaMikdash.
Why does the remaining goat not have to die?
The usual rule is: "Chatas sheniskapru be'aleha b'acheres" - if a person designated two animals for a single sin offering (for example, one was lost and then found after he had already gained atonement with the second), the animal that was not used must be put to death and may not be used. However, this rule applies to the sin offering of an individual, while here we are dealing with a communal sin offering, and regarding it the Mishnah concludes: "She'ein chatas tzibbur meisah" - in a communal sin offering the animal is not put to death; rather, it is left to graze and its value is used to bring a voluntary burnt offering.
The opinion of Rabbi Yehudah:
Rabbi Yehudah disagrees on two points:
Even in a communal sin offering, if the owners have already gained atonement with another animal, the animal that remains alive must be put to death, and it has the status of a sin offering that must die.
"Nishpach hadam - yamus hamishtalei'ach" - if after the sin offering goat was slaughtered its blood spilled, and another goat must be brought in its place, one must bring a new pair of goats and draw lots over them, since another slaughtering is required. The second goat of the new pair will be the one sent away, and the first goat that was to be sent away is like an animal whose owners gained atonement with another, since another has come to take its place - and therefore, in Rabbi Yehudah's view, it must be put to death.
"Meis hamishtalei'ach - yishafech hadam" - the Mishnah concludes: if the goat that is to be sent away died after the goat that is the sin offering to Hashem was slaughtered and its blood is ready at hand, the blood is poured out and may not be used. The basis of this law lies in the question of how long the goat sent away must remain alive, and the answer is: until the blood of the sin offering is sprinkled. Since it died before that, the blood is disqualified, and therefore it is poured out and another pair is brought.
In this law all agree: even though Rabbi Yehudah and the Sages disagree as to whether animals that are still alive become rejected and must be put to death, all agree that animals that have already been slaughtered are rejected and cannot be used, as in this case, where a new pair must be chosen.
In summary: In this Mishnah we learned the law of the two goats of Yom Kippur: ideally there is a mitzvah that they be identical in appearance, in height and in value, and that they be purchased together, yet even if they are not identical they are valid. We examined the law when one of them dies before the lottery and after it, the wording of the declaration establishing a substitute for the goat that died, the remaining goat that grazes until it becomes blemished with its value going to the donation fund because a communal sin offering is not put to death, and the opinion of Rabbi Yehudah that even a communal sin offering must die and that when the blood spills the goat sent away must die. Finally we learned the law that when the goat sent away dies the blood is poured out, because that goat must remain alive until the blood of the sin offering is sprinkled, and that regarding the rejection of slaughtered animals all agree.