The Mishna in Meseches Brachos 1:3 recounts the Machlokes between Beis Shammai and Beis Hillel on how one should read the Shema:
(Source provided by Sefaria.org)
בֵּית שַׁמַּאי אוֹמְרִים, בָּעֶרֶב כָּל אָדָם יַטּוּ וְיִקְרְאוּ, וּבַבֹּקֶר יַעַמְדוּ, שֶׁנֶּאֱמַר (דברים ו) וּבְשָׁכְבְּךָ וּבְקוּמֶךָ. וּבֵית הִלֵּל אוֹמְרִים, כָּל אָדָם קוֹרֵא כְדַרְכּוֹ, שֶׁנֶּאֱמַר (שם) וּבְלֶכְתְּךָ בַדֶּרֶךְ. אִם כֵּן, לָמָּה נֶאֱמַר וּבְשָׁכְבְּךָ וּבְקוּמֶךָ, בְּשָׁעָה שֶׁבְּנֵי אָדָם שׁוֹכְבִים, וּבְשָׁעָה שֶׁבְּנֵי אָדָם עוֹמְדִים.
Beis Shammai says: In the evening all people should recline and recite [Shema], and in the morning they should stand, since it says [in the verse (Deut. 6:7)], “And when you lie down and when you arise.” And Beis Hillel says: Each person may recite it in his usual way (posture), since it says (ibid.), “And when you walk on the road.” If so, why does it say “and when you lie down and when you arise”? —[It means:] at the time when people are lying down, and at the time when people are arising.
The Mishna proceeds to quote Rav Tarfon telling over his incident when following the opinion of Beis Shammai and the Sages' response:
אָמַר רַבִּי טַרְפוֹן, אֲנִי הָיִיתִי בָא בַדֶּרֶךְ, וְהִטֵּתִי לִקְרוֹת, כְּדִבְרֵי בֵית שַׁמַּאי, וְסִכַּנְתִּי בְעַצְמִי מִפְּנֵי הַלִּסְטִים. אָמְרוּ לוֹ, כְּדַי הָיִיתָ לָחוּב בְּעַצְמְךָ, שֶׁעָבַרְתָּ עַל דִּבְרֵי בֵית הִלֵּל:
Said Rabbi Tarfon: “I was once traveling on the road, and I reclined to recite [Shema] in accordance with the view of the school of Shammai, and [by doing so] I put myself in danger of [attack by] bandits.” They [the other Sages] said to him: “You would have deserved to be guilty for your own fate, since you went against the view of the school of Hillel.”
My Question:
What should have Rabbi Tarfon done? If he were to say the Shema while he was standing, would he not be going against the words of Beis Shammai?