In his answer to the question Is there any evidence that Rabbi Akiva's students fought with Bar Kochba, Jake cites Yerushalmi Taanit Taanis 4:5 and Medrash Rabba Eicha 2:4 as sources for the position that Bar Kochba was choked to death by a snake in punishment for his sins. What were Bar Kochba's perceived sins and why was this punishment appropriate?
The Yerushalmi in Taanis פרק ד הלכה ה and Medrash Raba in Eicha 2:4 inform us that Bar Kochava killed his uncle Rabbi Elazar Hamoda'i for no reason, except that he believed a scheming talebearing non-Jew.
The story - which is almost identical in both places - is as follows: (Translation from here)
Rabbi Elazar Hamodia's prayers sustained Betar for so long that Hadrian almost lost heart and returned home to Rome.
A sly Cuthean went to Hadrian and said: "My lord, as long as that old rooster wallows in ashes, you will not conquer the city. But I will do something that will enable you to subdue it today."
The Cuthean, spying for the Romans, entered Betar by way of a sewer. He entered the local synagogue, where he found Rabbi Eleazar deeply immersed in prayer, so much so that he was completely unaware of everything and everyone around him. The Cuthean acted like he was whispering in the ear of Rabbi Eleazar. Onlookers hurried to carry the tale to Bar Koziva: 'Your uncle, Rabbi Eleazar, is acting just like his teachers before him who wanted to appease the Romans; he wishes to surrender the city to Hadrian.'
The furious Bar Koziva summoned the Cuthean and asked: “What did you say to my uncle?”
The Jew-hating spy replied: 'If I tell you, the emperor will kill me; and if I do not tell you, you will kill me. It is better that I should kill myself and the secrets of the government be not divulged.'
Bar Koziva suspected that the old rabbi wanted to surrender the city. He ordered that Rabbi Elazar be brought to him. He accused him, “What did the Cuthean tell you?”
Rabbi Elazar answered: “I do not know what he whispered in my ear, nor did I hear anything, because I was standing in prayer and am unaware of what he said.”
Bar Koziva flew into a rage, kicking the frail fasting rabbi and killing him on the spot. A heavenly voice issued forth and proclaimed: '”You have paralyzed the arm of Israel and blinded their right eye!” This was a reference to Rabbi Elazar HaModai, in whose virtue Betar continued to exist. Betar and Bar Koziva no longer had the protection of the saintly rabbi's prayers and righteousness. The city was doomed and its leader was beheaded that very same day, Tisha B'Av, 135 CE, the tragic day that Betar fell and millions were murdered.
(Tranlsation from here)
והוה ר' אלעזר המודעי יושב על השק ועל האפר ומתפלל בכל יום ואומר רבון העולמים אל תשב בדין היום אל תשב בדין היום בעא אדריינוס מיזל ליה. אמר ליה חד כותיי לא תיזיל לך דאנא חמי מה מיעבד ומשלים לך מדינתא עאל ליה מן ביבא דמתינתא עאל ואשכח רבי אלעזר המודעי קאים מצלי. עבד נפשיה לחיש ליה בגו אודניה חמוניה בני מדינתא ואייתוניה גבי בן כוזבא. אמרון ליה חמינן ההן סבא משתעי לחביבך אמר ליה מה אמרת ליה ומה אמר לך אמר ליה אנא אמר לך מלכא קטל לי ואי לא אנא אמר לך את קטל יתי טב לי מלכא קטל יתי ולא את אמר ליה אמר לי דאננא משלים מדינתאי. אתא גבי רבי אלעזר המודעי אמר ליה מה אמר לך הדין כותייא אמר ליה לא כלום מה אמרת ליה א"ל לא כלום יהיב ליה חד בעוט וקטליה. מיד יצאת בת קול ואמרה (זכריה יא) הוי רעי האליל עזבי הצאן חרב על זרועו ועל עין ימינו זרועו יבוש תיבש ועין ימינו כהה תכהה הרגת את רבי אלעזר המודעי זרוען של כל ישראל ועין ימינם לפיכך זרועו של אותו האיש יבש תיבש ועין ימינו כהה תכהה. מיד נלכדה ביתר ונהרג בן כזובה
שָׁלשׁ שָׁנִים וּמֶחֱצָה הִקִּיף אַדְרִיָאנוּס קֵיסָר לְבֵיתָר, וְהָיָה שָׁם רַבִּי אֶלְעָזָר הַמּוֹדָעִי עָסוּק בְּשַׂקּוֹ וּבְתַעֲנִיתוֹ, וּבְכָל יוֹם וָיוֹם מִתְפַּלֵּל וְאוֹמֵר רִבּוֹנוֹ שֶׁל עוֹלָם אַל תֵּשֵׁב בַּדִּין הַיּוֹם. וּלְבַסּוֹף נָתַן דַּעְתּוֹ לַחֲזֹר, אֲתָא חַד כּוּתָאי וּמְצָאוֹ וְאָמַר לוֹ, אֲדוֹנִי, כָּל יוֹמִין דַּהֲדָא תַּרְנְגוֹלְתָּא מִתְגַּעְגַּע בְּקִיטְמָא לֵית אַתְּ כָּבֵישׁ לָהּ, אֶלָּא הַמְתֵּן לִי דַּאֲנָא עָבֵיד לָךְ דְּתַכְבְּשִׁנָּהּ יוֹמָא דֵין, מִיָּד עָלֵיל בֵּיהּ בְּבוּבֵיהּ דִּמְדִינְתָּא, וְאַשְׁכְּחֵיהּ לְרַבִּי אֶלְעָזָר דַּהֲוָה קָאֵים וּמַצְלֵי, עֲבַד גַּרְמֵיהּ לָחֵישׁ בְּאוּדְנֵיהּ דְּרַבִּי אֶלְעָזָר הַמּוֹדָעִי, אָזְלוּן וְאָמְרוּן לְבַר כוּזִיבָא חֲבִיבָךְ רַבִּי אֶלְעָזָר בָּעֵי לְאַשְׁלָמָא מְדִינְתָּא עִם אַדְרִיָּאנוּס, שְׁלַח וְאַתְיֵיהּ לְהַהוּא כּוּתָאי אֲמַר לֵיהּ מַאי אֲמַרְתְּ לֵיהּ. אֲמַר לֵיהּ אִין אֲנָא אָמַר לָךְ, מַלְכָּא קָטֵיל לֵיהּ לְהַהוּא גַבְרָא, וְאִין לֵית אֲנָא אָמַר לָךְ אַתְּ קָטֵיל לֵיהּ לְהַהוּא גַבְרָא, אֲבָל מוּטָב לִיקְטְלֵיהּ הַהוּא גַבְרָא לְגַרְמֵיהּ וְלָא תִתְפָּרְסִין מִיסְטֵירִין דְּמַלְכוּתָא. בֶּן כּוֹזִיבָא סָבַר בְּדַעְתֵּיהּ דִּבְעֵי לְאַשְׁלָמָא מְדִינְתָּא, כֵּיוָן דַּחֲסַל רַבִּי אֶלְעָזָר צְלוֹתֵיהּ שְׁלַח וְאַיְיתֵיהּ, אֲמַר לֵיהּ מָה אֲמַר לָךְ הָדֵין כּוּתָאי. אֲמַר לֵיהּ לֵית אֲנָא יָדַע מַה לְּחִישׁ לִי בְּאוּדְנָאי וְלָא שְׁמָעֵת לֵיהּ כְּלוּם דַּאֲנָא בִּצְלוֹתִי קָאֵימְנָא, וְלֵית אֲנָא יָדַע מָה הֲוָה אֲמַר. נִתְמַלֵּא רוּגְזֵיהּ לְבֶן כּוֹזִיבָא יְהַב לֵיהּ חַד בְּעִיטָא בְּרַגְלֵיהּ וְקָטְלֵיהּ, יָצְתָה בַּת קוֹל וְאָמְרָה (זכריה יא, יז): הוֹי רֹעִי הָאֱלִיל עֹזְבִי הַצֹּאן חֶרֶב עַל זְרוֹעוֹ וְעַל עֵין יְמִינוֹ, אָמְרָה לוֹ אַתָּה סִמִּיתָ זְרוֹעָן שֶׁל יִשְׂרָאֵל וְסִמִּיתָ עֵין יְמִינָן, לְפִיכָךְ זְרֹעוֹ שֶׁל אוֹתוֹ הָאִישׁ יָבוֹשׁ תִּיבָשׁ וְעֵין יְמִינוֹ כָּהֹה תִּכְהֶה. מִיָּד גָּרְמוּ עֲוֹנוֹת וְנִלְכְּדָה בֵּיתָר וְנֶהֱרַג בֶּן כּוֹזִיבָא
According to Rabbi Dr. Eliyahu Zini in his essay on Bar Kochva (in his book Etz Erez), pg. 301-307, Bar Kochva did not die because of his own sins but because of the sins of Am Yisrael: Internal conflicts so harsh that they led to people actually betraying one another to the Romans. In the aggadata, this is represented by the "Cuthite" fifth-column, symbolizing loss of national kinship (the Samaritans/Cuthites are people who wished to practice the Jewish religion without submitting to the Judaic ethnic identity, which is a key part of Judaism. They wished to maintain their own personal ethnic identity and to be set apart from the Jews1).
As Rabbi Zini wrote (my translation):
"Thanks to the words "immediately the sins caused" that are missing before us in the Yerushalmi, where instead there is only "immediately", we discover the source of the Rambam when he wrote "until he was killed through the sins"...we must denounce immediately that which is heard in many places, including in many yeshivot, that it was because of the sins of Bar Kochva that he was killed, meaning, through his killing of his uncle R' Elazar Ha'Modai. Such an understanding is simply an example of boorishness [עם הארצות] that cannot be exceeded...I shall base myself on a greater tree, as Rabbi Tzvi Yehudah Kook zt"l used to say: "The Rambam was a Sephardic sage, and by him, like all of the Sephardic sages who say "through the sins" [בעוונות] which refers to: The sins of he who says this, and not the sins of whom upon which this is said!! Meaning, when a Sephardic sage says "through the sins", he means "through my sins"...from this Yerushalmi and other places, we see that this expression was not unique only to the Sephardic sages, but this was the language of all of our rabbis, the sages of Yisrael [he continues and brings more examples of usage of this term in the Talmud]...
In light of this, the expression "through the sins" that is before us refers to the sins of the general community. Bar Kochva was not killed because of his own personal sins, but because of the sins of the generation in its entirety. The Holy One, Blessed is He gazed upon that generation, and decided that they weren't deserving of being redeemed, because of their sins, which were that internal hatred that originated in the rotten parts of the nation, parts that were even willing to assist our enemies so Bar Kochva wouldn't win. He who symbolizes this internal hatred is once again that "Cuthite"..."
Furthermore, when Bar Kochva repeated the verse "But You have rejected us, O God; God, You do not march with our armies" (Tehillim 60:12; Yerushalmi Taanit 24a) he did not mean "You have rejected us, therefore do not march with us" but the opposite, as was properly translated in the English: "You have rejected us and do not march with us (because you have rejected us)". Some commentators (Radak, Metzudat David, Malbim) explain this as a good thing - a fall that stems from not having been assisted by God shows us how much we do need Him. Alshich (if I'm not mistaken) explains the verse as a request from God: "Please do not make it seem as though we won on our own". In short, Bar Kochva's usage of this verse shows great faith in Hashem (not to mention that he used the respectful and very religious term of "Master of the Universe" (ריבוניה דעלמא) when speaking to Hashem).
Lastly, the snake that choked Bar Kochva is tied to the choking death (אסכרה) of the students of Rabbi Akiva and both are symbolic of the same thing: The internal conflicts among the Jews that "choked" (חנק) the high chances of the success of the rebellion.
Side-note: In light of Rabbi Zini's explanation, I think I can explain both why Bar Kochva suspected his uncle of betraying him and why the killing of Rabbi Elazar was not apparently considered a sin (or at least not bad enough to cause Bar Kochva's death):
Rabbi Elazar said in Avot 3:11:
"Rabbi Elazar of Modiin said...and one who annuls the covenant of our father Abraham, may he rest in peace...even though he has to his credit [knowledge of the] Torah and good deeds, he has not a share in the world to come."
While in a number of sources, there's evidence that the soldiers of Bar Kochva would abolish their circumcisions [מושכים בערלותיהם]. For example:
"...many abolishers were in the time of ben Kozeva and they all circumcised..." (Yerushalmi Yevamot 45a, my translation)
And according to Rabbi Mordechai Hakohen in his book "אישים ותקופות" (People and Eras), pg. 108, the story that appears in Eicha Rabbah 2:4 and Yerushalmi Taanit 24b should be understood thus (my translation):
"Two brothers lived in Kefar Charocha and no Roman who passed by the village was allowed to live. [One time], they said they would use the medicine of the circumcision [i.e., would abolish their circumcision], in order to steal the crown of Hadrian to place it upon the head of Shimon [Bar Kochva]..."
Therefore, we find that Bar Kochva and his uncle disagreed on what was and what wasn't proper to do during wartime. Bar Kochva was for all-out, no-holds barred war, whilst his uncle was more moderate and criticized those who would abolish their circumcision, even if it was for the important cause of disguising themselves as Roman soldiers to assist in the war effort. Moreover, Rabbi Elazar was likely a student of Rabban Yochanan ben Zakkai (Bava Batra 10b) who of course was the person who snuck out of Yerushalayim to meet with the Romans and strike a deal with them. He was later criticized for this action by none other than Bar Kochva's biggest supporter, Rabbi Akiva (Gittin 56b).
Now we can perhaps imagine what may have been going on in Bar Kochva's head: He hears troubling rumors about his moderate uncle, who happens to be the student of Rabban Yochanan, who seemingly turned his back on the rebels of the Great Revolt, and his uncle is staying, for some reason, in the last stronghold of the rebellion, Beitar. Alarms go off in his head, as he fears that his uncle may be planning to strike a deal with the Romans - perhaps sparing some of the Jews in return for info on how to bring about the downfall of Beitar, Bar Kochva and his men.
Interrogating his uncle in order to attempt to deduce the truth is similar to King David's interrogation of the Amalekite youth (Shmuel 2:1:2-16): In Bar Kochva's mind, at that moment, Rabbi Elazar was suspected of being a rebel against the throne (מורד במלכות) bent on decimating the rebellion. In a sense, he was also a rodef (רודף) and a danger to the public. Whether Bar Kochva intended to kill his uncle when he kicked him or not isn't so important because Rabbi Elazar was found guilty of treason, so he should have received capital punishment either way.
1 Avraham Korman wrote in his book "Denominations and Cults in Judaism" (זרמים וכתות ביהדות), pg. 184, that in his view, the verse "...It is not for you and us to build a House to our God..." (Ezra 4:3), which is the Olim's reply to the Samaritans after they requested to join in with the building of the Temple, that the Olim meant that "there is no we and you - no two Jewish ethnicities. Either you become fully Jewish and embrace our ethnicity and you can build with us, or not - and you can't, and you have no place in the Temple worship". As we know, the Samaritans refused, which led to many years of strife between the two groups.