To prevent people going from East Berlin to West Germany.
After World War 2 both Germany and Berlin were divided into 4 zones of occupation.
When the Cold War began the American, British and French zones joined to form West Germany and the Soviet zone became East Germany. The same happened in Berlin.
However Berlin was well within the Soviet zone, subsequently East Germany. As living standards in the west outstripped the East and authoritarian governments ruled East Germany and other communist bloc states, then people increasingly went from East to West Berlin, then flew out to West Germany.