Labour has opened the door to reversing Britain's decision to leave the European Union, by backing a potential second referendum.