It is hard to parse. Let’s walk through it.
帰京する飛行機
We are talking about an airplane. It is modified by 帰京する. But 帰京する is usually used for a person. Who might that be? We don’t know yet. Let’s leave this judgment for later. Whoever it is, the relation between that person and the airplane is clear enough. They are going to take that plane, or flight.
(Xが)帰京する(ために乗る)飛行機
X’s flight back to Tokyo
What about this flight?
[帰京する飛行機]の直前
Since we are talking about a flight, this must be referring to a time immediately before the departure of that flight.
帰京する飛行機の直前
immediately before the departure of X’s flight back to Tokyo
What happens at that time?
[帰京する飛行機の直前]に到着する
Something arrives. What does?
[帰京する飛行機の直前に到着する]時刻
It’s again a time. 到着する時刻 would mean a time at which something arrives. But we already know when that something arrives. Let’s read on.
[帰京する飛行機の直前に到着する時刻]のバス
So it is a bus that arrives. Then how is it related to 時刻? It must be the departure time of the bus.
帰京する飛行機の直前に到着する時刻のバス
a bus whose departure time is such that it arrives immediately before the departure of X’s flight back to Tokyo
What about this bus?
[帰京する飛行機の直前に到着する時刻のバス]にしか
The bus is a target of something. しか means it is the only target. But しか is always matched with a negative expression. Let’s read on.
[帰京する飛行機の直前に到着する時刻のバス]にしか間に合わなかった
So someone failed to make it in time for all but that bus. It must be the same person going back to Tokyo.
帰京する飛行機の直前に到着する時刻のバスにしか間に合わなかった
X failed to make it in time for all but the bus whose departure time is such that it would arrive immediately before the departure of X’s flight back to Tokyo
Let’s see how the sentence ends.
[帰京する飛行機の直前に到着する時刻のバスにしか間に合わなかった]こともあります。
So this person is talking about a past experience. Though we are not completely sure, they must be talking about their own experience. That means X turned out to be the speaker.
帰京する飛行機の直前に到着する時刻のバスにしか間に合わなかったこともあります。
There was also a time when I failed to make it in time for all but the bus whose departure time is such that it would arrive immediately before the departure of my flight back to Tokyo.
In a little more idiomatic English:
There was a time when I was so late that I only managed to catch the last bus for my flight back to Tokyo.
[Edit]
OK, it turned out the sentence didn’t end there but continued after こともあり.
[帰京する飛行機の直前に到着する時刻のバスにしか間に合わなかった]こともあり、〜
The speaker must be explaining circumstances behind something.
帰京する飛行機の直前に到着する時刻のバスにしか間に合わなかったこともあり、〜
Considering also that I couldn’t make it in time for all but the bus whose departure time is such that it would arrive immediately before the departure of my flight back to Tokyo, …
In a little more idiomatic English:
As I could only take the last bus for my flight back to Tokyo, …
〜しか〜なかった
in it. Does this much hint help you understand the sentence better?