If the entrance is not free, it seems from the Gemara that you cannot enter. A similar case is cited in Gemara Yoma 35b.
Yoma 35b:
אמרו עליו על הלל הזקן שבכל יום ויום היה עושה ומשתכר בטרעפיק חציו היה
נותן לשומר בית המדרש וחציו לפרנסתו ולפרנסת אנשי ביתו פעם אחת לא מצא
להשתכר ולא הניחו שומר בית המדרש להכנס עלה ונתלה וישב על פי ארובה כדי
שישמע דברי אלהים חיים מפי שמעיה ואבטליון אמרו אותו היום ערב שבת היה
ותקופת טבת היתה וירד עליו שלג מן השמים כשעלה עמוד השחר אמר לו שמעיה
לאבטליון אבטליון אחי בכל יום הבית מאיר והיום אפל שמא יום המעונן הוא
הציצו עיניהן וראו דמות אדם בארובה עלו ומצאו עליו רום שלש אמות שלג
פרקוהו והרחיצוהו וסיכוהו והושיבוהו כנגד המדורה אמרו ראוי זה לחלל עליו
את השבת
It was reported about Hillel the Elder that every day he used to work
and earn one tropaik, half of which he would give to the guard at
the House of Learning, the other half being spent for his food and for
that of his family.
One day he found nothing to earn and the guard at the House of
Learning would not permit him to enter.
He climbed up and sat upon the window, to hear the words of the
living God from the mouth of Shemayah and Abtalion - They say, that
day was the eve of Sabbath in the winter solstice and snow fell down
upon him from heaven.
When the dawn rose, Shemayah said to Abtalion: Brother Abtalion,
on every day this house is light and to-day it is dark, is it perhaps
a cloudy day.
They looked up and saw the figure of a man in the window.
They went up and found him covered by three cubits of snow.
They removed him, bathed and anointed him and placed him opposite the
fire and they said: This man deserves that the Sabbath be profaned on
his behalf.
Conclusion, if the Shiur is audible outside the door, you can hear, but maybe that you cannot go into the bet midrash.
An other topic is if only morally accredited students can be admitted (Berachot 28a):
For Rabban Gamaliel had issued a proclamation [saying].
No disciple whose character does not correspond to his exterior may
enter the Beth ha-Midrash.
On that day many stools were added.
Takeway (thanks to @DoubleAA) the Bet Midrash is entitled to set the conditions of admission to Shiur.