I recently studied Masechet Berachot in school. And I learnt that one shouldn't pray in ruins. But isn't the Kotel the ruins of the Beit HaMikdash?
Firstly the Kotel wasn't part of the ruins of the Beit HaMikdash, according to popular opinion.
It's a retainer wall holding up the Temple Mount platform. The Bet HaMikdash ruins morphed into archeology a long time ago.
Secondly not every old wall is a ruin which the dictionary defines as a building or place in a state of decay, collapse, or disintegration. The Kotel is a solid wall.
Thirdly, and more to the point, the Gemara you quote (Berachot 3a) gave 3 reasons why not to pray in a ruin:
ת''ר מפני שלשה דברים אין נכנסין לחורבה מפני חשד מפני המפולת ומפני המזיקין
Suspicion: People meet shady characters in ruins; why else would they go there? Clearly does not apply to the very public Kotel.
It could collapse suddenly. This clearly does not apply to the Kotel.
It's dangerous - Mazikin (demons?) live in ruins. Not applicable to the Kotel as it's not an abandoned building.
Since "one shouldn't pray in ruins" has reasons, and none apply to the Kotel, I see no reason why not to pray there.