The answer involves swords and horse-drawn wagons.
The practice dates back centuries. In right-handed societies, keeping to the left allowed horsemen to keep their dominant hand free to greet others or defend themselves with a sword. The shift to the right in countries like the US and France was partly a post-revolutionary rejection of old norms and also influenced by large freight wagons pulled by teams of horses.