When you go out drinking you would have noticed that all the liquor is kept behind the barman on a wall. Of course, they do not expect you to jump over the counter and go for it.
Things were not as civil back in the 1200s. Mobility was high, nothing called a passport existed and you could leave for a land far far away. So travellers were not worried about civility and at times they would go behind the counter and steal liquor or consume it and refuse to pay for it. To ensure this did not happen, tavern owners would put their liquor inside a prison.
Bar is a word derived from the French ‘Barre’ which means rod. The liquor was literally behind bars and thus the outlet started to be called Bar.